Reputation: 1091
I've got the following data:
vpri=seq(2,16,2)
vfb = 1.87*vpri
I want to make a linear regression that goes out from vfb = 1 to 100 on the y axis. I've tried a few things and wound up with this code:
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))
However, the truth is that the value of 60 I have in the arugments for xlim
is something I got only after guessing and checking.
I would like to get the stat_smooth
object to treat the y axis as the judge of what 'fullrange
' really is, not the x axis. furthermore, once I get this far, I would then need to add custom tick-spacing to both axes (since the 25/division is too coarse) , but I know that R will throw a fit when I use xlim
(or ylim
) as the thing to drive stat_smooth
and then ask it to handle the ticks later on with a scale_x_continuous
, or a scale_y_continuous
Upvotes: 2
Views: 2346
Reputation: 1091
This did it:
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)
Upvotes: 2