Hi Michael,
The problem is that geom_segment is looking for colour=source, but
there is no source variable in df2. You should only but common
aesthetic mappings in the ggplot2 call, otherwise you will have to
override theme. Here is how I would do it:
ggplot(data = df1) +
geom_point(aes(x = days.c, y = int, colour = source)) +
geom_segment(aes(x = days.lm, y = int.lm, xend = days.lmm, yend =
int.lmm), data = df2)
Alternatively you can leave your original setup and override the color
mapping in geom_segment. You've tried to do this with group=NA, but it
is the color mapping you need to override, not the grouping:
ggplot(data = df1, aes(x = days.c, y = int, colour = source)) +
geom_point() +
geom_segment(data = df2, aes(x = days.lm, y = int.lm, xend =
days.lmm, yend = int.lmm, colour=NULL))
Best,
Ista
On Mon, Mar 18, 2013 at 7:13 AM, Michael Kubovy <
mk...@me.com> wrote:
> R version 2.15.3 (2013-03-01)
> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] grid splines stats graphics grDevices utils datasets
> methods base
>
> other attached packages:
> [1] languageR_1.4 doBy_4.5-5 reshape2_1.2.2 effects_2.2-4
> colorspace_1.2-1 WWGbook_1.0.1
> [7] sos_1.3-5 brew_1.0-6 gridExtra_0.9.1 robustbase_0.9-7
> multcomp_1.2-15 mvtnorm_0.9-9994
> [13] gplots_2.11.0 KernSmooth_2.23-9 caTools_1.14 gdata_2.12.0
> gtools_2.7.0 scales_0.2.3
> [19] Hmisc_3.10-1 survival_2.37-4 MPDiR_0.1-12 R.utils_1.19.5
> R.oo_1.13.0 R.methodsS3_1.4.2
> [25] flexmix_2.3-10 plyr_1.8 car_2.0-16 nnet_7.3-5
> xtable_1.7-1 arm_1.6-05
> [31] foreign_0.8-52 abind_1.4-0 R2WinBUGS_2.1-18 coda_0.16-1
> lme4_0.999999-0 Matrix_1.0-11
> [37] lattice_0.20-13 MASS_7.3-23 gmodels_2.15.3 tikzDevice_0.6.2
> filehash_2.2-1 stringr_0.6.2
> [43] ggplot2_0.9.3.1 codetools_0.2-8 knitr_1.1
>
> loaded via a namespace (and not attached):
> [1] bitops_1.0-4.2 cluster_1.14.3 dichromat_2.0-0 digest_0.6.3
> evaluate_0.4.3 formatR_0.7
> [7] gtable_0.1.2 labeling_0.1 modeltools_0.2-19 munsell_0.4
> nlme_3.1-108 proto_0.3-10
> [13] RColorBrewer_1.0-5 stats4_2.15.3 tools_2.15.3
>
> Here is a reproducible example and error at the bottom.
>
> library(lme4)
>
> data(sleepstudy)
>
> sleepstudy$Days.c <- with(sleepstudy, Days - median(Days))
>
> df <- as.data.frame(coef(summary(lmList(Reaction ~ Days.c | Subject,
> sleepstudy))))
>
> df <- df[, c(1, 5)]
>
> names(df) <- c('int', 'days.c')
>
> mm1 <- lmer(Reaction ~ Days.c + (Days.c | Subject), sleepstudy)
>
> cc1 <- as.data.frame(coef(mm1)[["Subject"]])
>
> names(cc1) <- c('int', 'days.c')
>
> df1 <- rbind(df,cc1)
>
> df1$source <- factor(rep(c('lm', 'lmm'), each = 18))
>
> df2 <- cbind(df,cc1)
>
> names(df2) <- c('int.lm', 'days.lm', 'int.lmm', 'days.lmm')
>
> library(grid)
>
> library(ggplot2)
>
> ggplot(data = df1, aes(x = days.c, y = int, colour = source)) + geom_point()
> + geom_segment(data = df2, aes(x = days.lm, y = int.lm, xend = days.lmm,
> yend = int.lmm, group = NA))
>
> #Error in data.frame(x = c(21.7647024242424, 2.26178545454545,
> 6.11489878787879, :
>
> # arguments imply differing number of rows: 18, 0
>
>
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
>
https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email
ggp...@googlegroups.com
> To unsubscribe: email
ggplot2+u...@googlegroups.com
> More options:
http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
ggplot2+u...@googlegroups.com.
> For more options, visit
https://groups.google.com/groups/opt_out.
>
>