As you can probably imagine, this don't look like I am hoping, which is that my labels are the letters showing significant differences (named ".group") being above their associated/respective plot types within each Water Depth. I have spent hours and hours trying out a variety of different options, none of which have worked and most of which have produced something rather visually funky (great for entertainment, less so for papers). I know it is only telling me to do what I tell it to do, but I am having difficulty understanding how to map the desired aesthetics to the the desired locations on the figure. Any help would be greatly appreciated!
--
Check out our R resources at http://d-rug.github.io/
---
You received this message because you are subscribed to the Google Groups "Davis R Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to davis-rug+...@googlegroups.com.
Visit this group at https://groups.google.com/group/davis-rug.
For more options, visit https://groups.google.com/d/optout.
Here is a revision of the original message:
I am trying to add the labels for significant differences between combinations of two factors, and am having some difficulties.I have a negative binomial mixed model with multiple nesting levels and random factors, with a count response. All of my predictors are categorical. I chose my final model and ran this through lsmeans() and cld() to do pairwise comparisons for significant factors and interactions.When I have one factor with any number of levels, my code works fine.For example (where test5 is my glmm, and SamplePer is the factor of interest):SamplePer = lsmeans(test5, ~ SamplePer)SamplePer = cld(SamplePer, alpha=0.10, Letters=letters, adjust="tukey")Which gives an object of type 'summary_emm' and 'data.frame' looking like this:SamplePer lsmean SE df asymp.LCL asymp.UCL .groupApr1 -0.4863283 0.2632676 NA -1.1789954 0.2063388 aMar2 0.1105724 0.2221710 NA -0.4739680 0.6951129 abMar1 0.4999976 0.2771670 NA -0.2292395 1.2292346 bFeb2 0.8025046 0.2814722 NA 0.0619406 1.5430687 bcFeb1 1.5699948 0.2515543 NA 0.9081458 2.2318437 cdJan 1.8281466 0.2520075 NA 1.1651054 2.4911879 d
Let's not even get into the topic of p-values please, I know. LOL. Anyway.
### Plotggplot(SamplePer,aes(x = SamplePer,y = lsmean,label = .group)) +geom_point(shape = 15,size = 4,position = pd) +geom_errorbar(aes(ymin = asymp.LCL,ymax = asymp.UCL),width = 0.2,size = 0.7,
position = position_dodge(0.4)) +
geom_text(nudge_x = c(0, 0, 0, 0),nudge_y = c(4, 4, 4, 4),color = "black")+scale_color_manual(values = c("blue", "red"))
Results in the attached .tiff file "SamplerPer".
BUT, when I try to do this for an interaction term, with this code:Plot_WaterDepth = lsmeans(test5, ~ PlotType | WaterDepth)Plot_WaterDepth = cld(Plot_WaterDepth, alpha=0.10, Letters=letters, adjust="tukey")
And try to plot with this:
ggplot(Plot_WaterDepth,aes(x = WaterDepth,y = lsmean,color = PlotType,label = .group)) +geom_point(shape = 15,size = 4,position = pd) +geom_errorbar(aes(ymin = asymp.LCL,ymax = asymp.UCL),width = 0.2,size = 0.7,
position = position_dodge(0.4)) +
geom_text(nudge_x = c(0, 0, 0, 0),nudge_y = c(4, 4, 4, 4),color = "black")+ #HERE IS WHERE THINGS GO WRONG.scale_color_manual(values = c("blue", "red", "green"))
I get the attached "Plot.WaterDepth" jpeg.
As you can probably imagine, this doesn't look like I was hoping it would, which is that my labels would be the letters showing significant differences (named ".group") being above their associated/respective plot types within each Water Depth. I have spent hours trying out a variety of different options, none of which have worked and most of which have produced something rather visually funky (great for entertainment, less so for papers). I know it is only telling me to do what I tell it to do, but I am having difficulty understanding how to map the desired aesthetics to the the desired locations on the figure. Any help would be greatly appreciated!
Thank you so much! I hope this post is more readable. Thanks.
--
Check out our R resources at http://d-rug.github.io/
---
You received this message because you are subscribed to the Google Groups "Davis R Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to davis-rug+...@googlegroups.com.
Visit this group at https://groups.google.com/group/davis-rug.
For more options, visit https://groups.google.com/d/optout.
library(ggplot2)## Load data ----Plot_WaterDepth = read.csv('Plot_WaterDepth.csv')## For solution 2, y position of the labelsPlot_WaterDepth$label_y = Plot_WaterDepth$lsmean + 1## Define underlying plot, w/out labels ----dodge = position_dodge(width = .5)basic_plot = ggplot(Plot_WaterDepth,
aes(x = WaterDepth,y = lsmean,
group = PlotType,
color = PlotType,label = .group)) +
geom_errorbar(aes(ymin = asymp.LCL,ymax = asymp.UCL),
position = dodge)## Solution 1 ----## Labels at a fixed heightbasic_plot +geom_text(aes(y = 4), color = 'black', position = dodge)## Solution 2 ----## Labels at variable height, relative to corresponding valuesbasic_plot +geom_text(aes(y = label_y), color = 'black', position = dodge)