[R] Side by side scatter plots with specified regression lines
Sigrid
s.stenerud at gmail.com
Fri Jun 24 19:00:49 CEST 2011
Thank you so much for that. I now have this graphs, by using these commands
*p=ggplot(data = test, aes(x = YEAR, y = TOTAL, colour = TREATMENT)) +
geom_point() + geom_smooth(method = "lm", se=FALSE) + facet_wrap(~COUNTRY)
> p +scale_x_continuous(limits=c(1,4))*
http://r.789695.n4.nabble.com/file/n3623055/graph.gif
I would also like to:
1.) change the headline for the faced wraps ‘high’ and ‘low’. Is there any
other way of doing that other than changing the names in the dataset?
2.) show the slope and intercept next to the treatments labels on the right
side. The geom_text only works inside the graph. I know I can change the
names of the treatments in the data set to include the intercept and slope,
but that seems like a detour for what I want to achieve.
3.) avoid the decimals on the x-axis. I would prefer the ticks to be
(1,2,3,4). How is that done?
4.) change the lines. The look of the graph is exactly what I am after
(except those minor changes mentioned above). However, the slopes and
intercepts are not the same as what I got when I completed an ancova model.
*> coef(lm(formula = TOTAL~ TREATMENT + YEAR + COUNTRY + TREATMENT:YEAR,
data= test))*
.... r gives the values for the different intercepts and slopes...
/a./ I’ve tried adding an abline that specifies slope and intercept. But
then I would have to specify which of the facet wraps that the line belongs
to, as it turns up in both grids. Is that possible in qqplot2?
*> p=ggplot(data = test, aes(x = YEAR, y = TOTAL, colour = TREATMENT)) +
geom_point() + facet_wrap(~NITROGEN)*
#this is the treatment A, but should only be displayed in the right graph
(low).
*p + geom_abline(intercept = 81.476,slope=47.2667, colour = "red", size =
1)*
http://r.789695.n4.nabble.com/file/n3623055/graph2.gif
/b./ Another option I’ve tried is to specify the model in the stat_smooth
and geom_smooth commandsm=, but in both cases I get an error message.
*> p + stat_smooth(method = "lm", formula = TOTAL ~ TREATMENT + YEAR +
COUNTRY + TREATMENT:YEAR)+
+ geom_point()*
Error in model.frame.default(formula = formula, data = data, weights =
weight, :
variable lengths differ (found for 'COUNTRY')
Thank you for all help and creative solutions.
Sigrid
--
View this message in context: http://r.789695.n4.nabble.com/Side-by-side-scatter-plots-with-specified-regression-lines-tp3592473p3623055.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list