【发布时间】:2016-10-30 10:20:57
【问题描述】:
我想使用 ggplot 绘制两个变量。稍后我想使用非线性拟合,但是我遇到了一个我不完全理解的错误消息的问题。我可以看到其他人有类似的问题,但我可能不够聪明,无法理解答案
我有一个包含 4 个变量的数据集 ost。数据集中没有 NA。
使用 ggplot2 我想用回归线绘制数据。为简单起见,我从简单的线性回归开始
library(ggplot2)
qt_int <- c(404, 402, 426, 392, 418, 410)
rr <- c(1000, 958, 982, 752, 824, 844)
gender <- c('male','female','female','female','female','female')
deltnr <- c(10445, 1022, 9122, 60, 246, 306)
df = data.frame(deltnr, gender, qt_int, rr)
p <- ggplot(df, aes(rr, qt_int))
p <- p + geom_point (size = 2)
p <- p + stat_smooth(method = "lm", formula = qt_int ~ rr)
p
我收到以下警告消息:
警告消息:1:“newdata”有 80 行,但发现的变量有 6702 行 2:
stat_smooth()中的计算失败:参数 antyder forskelligt antal rækker: 80, 6 [En: 参数建议 不同的行数:80、6]
奇怪的是,如果我省略公式,它会起作用(但我想稍后进行非线性拟合,所以我必须让它起作用)
我错过了什么?
【问题讨论】:
-
好吧,we 缺少
int99(即您的代码不可重现)并且 you 在ggplot函数中使用$调用这不是ggplot真正起作用的方式。