[R] grey colored lines and overwriting labels i qqplot2
djmuser at gmail.com
Fri Jul 15 18:32:04 CEST 2011
What did you do and what do you mean by 'add[ing] those 14 lines'? A
reproducible example would be helpful. I've used plyr successfully to
get model coefficients before, so I'm interested in what you mean by
'ddply is not the right method to add my model.' Here's a toy
reproducible example to counter your claim:
df <- data.frame(gp = rep(1:5, each = 10), x = 1:10,
y = 1.5 + 2 * rep(1:10, 5) + rnorm(50))
# function to generate the model coefficients for a generic data frame
lmfun <- function(d) coef(lm(y ~ x, data = d))
# Apply the function to each sub-data frame associated with groups:
ddply(df, .(gp), lmfun)
gp (Intercept) x
1 1 1.2481481 2.011974
2 2 1.3125070 1.977223
3 3 0.5988811 2.212524
4 4 0.8575467 2.075925
5 5 2.1428869 1.903015
Internally, ddply() splits df into five sub-data frames corresponding
to each level of gp. The function lmfun() is applied to each sub-data
frame. Notice that the function argument is a data frame (observe that
data = d inside lm()). It is often advantageous to run lm() by group,
exporting the output to a list of lists (since the output from lm() is
a list), from which plyr can use the ldply() function to pick off
pieces of output from each group. I've done this several times before
in this forum, so I'm not going to repeat it here.
If you post what you tried that didn't work, perhaps I or someone else
can get it to work for you. As mentioned above, reproducible code and
data (with dput()) is ideal.
On Fri, Jul 15, 2011 at 5:26 AM, Sigrid <s.stenerud at gmail.com> wrote:
> Okay, seems like ddply is not the right method to add my model. That is okay,
> though. I already calculated the slopes and intercepts fore each for the
> treatments and country. How can I add those 14 lines?
> View this message in context: http://r.789695.n4.nabble.com/grey-colored-lines-and-overwriting-labels-i-qqplot2-tp3657119p3669823.html
> Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help