楼主: 昨天的事
13904 10

[问答] 求助:R语言画抛物线 [推广有奖]

  • 0关注
  • 1粉丝

本科生

13%

还不是VIP/贵宾

-

威望
0
论坛币
33 个
通用积分
0.0005
学术水平
0 点
热心指数
5 点
信用等级
0 点
经验
268 点
帖子
21
精华
0
在线时间
95 小时
注册时间
2014-2-6
最后登录
2018-8-2

楼主
昨天的事 发表于 2015-1-25 10:41:10 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
用plot(x,y)画出散点图,发现x和y是二次函数的关系,如何画出抛物线的拟合图
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:R语言 抛物线 二次函数 plot 散点图 抛物线 散点图 二次函数 如何

沙发
358463121 发表于 2015-1-25 13:27:54
plot(x,y,"l")
Arguments to be passed to methods, such as graphical parameters (see par). Many methods will accept the following arguments:

type
what type of plot should be drawn. Possible types are

"p" for points,

"l" for lines,

"b" for both,

"c" for the lines part alone of "b",

"o" for both ‘overplotted’,

"h" for ‘histogram’ like (or ‘high-density’) vertical lines,

"s" for stair steps,

"S" for other steps, see ‘Details’ below,

"n" for no plotting.

藤椅
昨天的事 发表于 2015-1-25 15:02:07
358463121 发表于 2015-1-25 13:27
plot(x,y,"l")
Arguments to be passed to methods, such as graphical parameters (see par). Many metho ...
参数“l”是把所有点连起来,没办法画出二次函数的拟合曲线

板凳
gni456 发表于 2015-1-25 15:27:38
fit <- lm(y~x+I(x^2))
plot(x,y)
lines(x,fitted(fit))


报纸
jiangbeilu 学生认证  发表于 2015-1-26 09:08:32
  1. curve(x^2,-100,100)
复制代码

地板
昨天的事 发表于 2015-1-27 00:38:50
gni456 发表于 2015-1-25 15:27
fit
画不出拟合的二次曲线

7
gni456 发表于 2015-1-27 10:30:25
昨天的事 发表于 2015-1-27 00:38
画不出拟合的二次曲线
不应该啊 Rplot01.png

8
昨天的事 发表于 2015-1-28 21:35:51
gni456 发表于 2015-1-27 10:30
不应该啊
  1. a<-data.frame(
  2. X=c(10.0, 8.0, 13.0, 9.0, 11.0, 14.0, 6.0, 4.0, 12.0, 7.0, 5.0),
  3. Y=c(9.14,8.14, 8.74,8.77,9.26,8.10,6.13,3.10, 9.13,7.26,4.74))
  4. lm2.sol<-lm(Y2~X+I(X^2)); summary(lm2.sol)
  5. plot(a$X,a$Y)
  6. lines(a$X,fitted(lm2.sol))
复制代码

抛物线拟合图.png (12.41 KB)

抛物线拟合图.png

9
gni456 发表于 2015-1-29 09:48:15
昨天的事 发表于 2015-1-28 21:35
先把数据按X从小到大排序再用lines()就好了
X <- c(10.0, 8.0, 13.0, 9.0, 11.0, 14.0, 6.0, 4.0, 12.0, 7.0, 5.0)
Y <- c(9.14,8.14, 8.74,8.77,9.26,8.10,6.13,3.10, 9.13,7.26,4.74)
a <- data.frame(X,Y)
a <- a[order(X), ]
fit <- lm(Y~X+I(X^2),data=b)
plot(X,Y)
lines(a$X,fitted(fit))
l Rplot02.png

10
昨天的事 发表于 2015-1-29 10:11:12
gni456 发表于 2015-1-29 09:48
先把数据按X从小到大排序再用lines()就好了
X
非常感谢

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-5 13:38