好了,我已经尝试了所有可能的组合,在Googling上搜索了任何其他方法,以便在我的图表上获得最佳拟合线(只有2个数据点)。
我已经从Excel导入了我的数据集Seal_Tide_data_set。在我尝试添加趋势线之前,绘图代码一直有效,是的,我已经将趋势线代码添加到现有的绘图代码中,这样它们就在同一条线上-也尝试了不使用并一直收到错误信息"plot.new尚未被调用“
下面是我的代码(没有趋势线):
Seal_Tide_data_set
library(ggplot2)
ggplot(Seal_Tide_data_set,aes(time,numSeals)) +
geom_point() +
labs(x="Number of Seals",y="Time of Day") + ylim(0,14)这样就可以得到一个图,现在我只需要添加一条最适合的线,所以到目前为止我所知道的是abline()函数是最好的
我试过了:
Seal_Tide_data_set
library(ggplot2)
ggplot(Seal_Tide_data_set,aes(time,numSeals)) +
geom_point() + labs(x="Number of Seals",y="Time of Day") +
ylim(0,14) +
abline(lm(Seal_Tide_data_set$time~Seal_Tide_data_set$numSeals))并获得以下错误代码:
Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) :
plot.new has not been called yet我也尝试过:(我真的不希望这样做,因为r不知道我用abline函数引用的是什么图)
Seal_Tide_data_set
library(ggplot2)
ggplot(Seal_Tide_data_set,aes(time,numSeals)) +
geom_point() + labs(x="Number of Seals",y="Time of Day") +
ylim(0,14)
abline(lm(Seal_Tide_data_set$time~Seal_Tide_data_set$numSeals))我真的不确定还可以尝试什么(我也尝试了其他行函数,比如line ()等等,上面的两种格式被abline()替换了)
非常感谢您的帮助!(:
发布于 2018-05-02 08:04:35
尝试在您的ggplot2规范中添加+ geom_smooth(method="lm")。
abline()是为基础图设计的,不能与ggplot2一起使用。
https://stackoverflow.com/questions/50125404
复制相似问题