我收到了以下数据:
vpri=seq(2,16,2)
vfb = 1.87*vpri
我想在y轴上进行从vfb = 1到100的线性回归。 我已尝试了一些事情并完成了这段代码:
ggplot(df, aes(x=vpri, y=vfb)) +geom_point(shape=1) +
xlim(0,60) +
stat_smooth(method="lm",fullrange = TRUE) +
scale_y_continuous(breaks=seq(0,100,5))
然而,事实是我在xlim
的句子中所拥有的60的值是我猜测和检查后得到的。
我想让stat_smooth
对象将y轴视为判断' fullrange
'真的是,不是x轴。此外,一旦我走到这一步,我就需要在两个轴上添加自定义的刻度间距(因为25 /除法太粗糙),但我知道当我使用xlim
时R会抛出一个拟合(或ylim
)作为驱动stat_smooth
的内容,然后要求它使用scale_x_continuous
或scale_y_continuous
答案 0 :(得分:1)
这样做了:
ggplot(df, aes(x=vpri, y=vfb)) +geom_point(shape=1) + # Use hollow circles
scale_x_continuous(limits=c(1,60),breaks=seq(0,60,5)) +
scale_y_continuous(breaks=seq(0,2*60,5)) +
stat_smooth(method="lm",fullrange = TRUE)