[R] changing graphs in qqplot2

Sigrid s.stenerud at gmail.com
Sun Jun 26 22:21:29 CEST 2011


This is what I have now so far.

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/n3626510/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/n3626510/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 

(I am re-posting as I've gotten more information on what I wanted to know
under my last post, but my new problems are not reflected by the subject and
I feel like some people would be missing out a chance of helping me out. I
hope it is okay.)

--
View this message in context: http://r.789695.n4.nabble.com/changing-graphs-in-qqplot2-tp3626510p3626510.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list