3 Compact letter display(CLD) three way ANOVA and visualisation with R and ggplot2 part III
Вставка
- Опубліковано 6 жов 2024
- #rprogramming #rprogramming #anovaplot #ggplot2 #emmeans #cld #compactletterdisplay
In this tutorial, you will learn how to effectively apply Three-Way ANOVA to analyze your data and then compute the Critical Difference (CLD) values. We will dive into the world of R programming and utilize the powerful ggplot2 library to create stunning visualizations of the CLD results. Join us to unlock the secrets of statistical analysis and take your data interpretation skills to the next level!
This is a 3 part video tutorial
part 1 : one way ANOVA and CLD : • I - Compact Letter Dis...
part 2: Two way Anova and CLD : • 2 Compact letter displ...
part 3: Three way Anova and CLD : • 3 Compact letter displ...
code
compact letter display using ggplot2
library(palmerpenguins)
library(emmeans)
library(multcomp)
convert to data frame
penguins= as.data.frame(penguins)
head(penguins)
mod3 = aov(flipper_length_mm~species+ island+sex, penguins)
summary(mod3)
emmean = emmeans(mod3,specs = c("species","island","sex"))
emmean_cld = cld(emmean,Letters=letters)
library(ggplot2)
library(ggpattern)
p = ggplot(emmean_cld,aes(species,emmean,fill=island,pattern=sex,label=.group))+
geom_col_pattern(position="dodge", alpha=0.5, color="grey60",
pattern_fill="black",
pattern_density=0.1,
pattern_angle=45,
pattern_spacing=0.025,
pattern_key_scale_factor=0.6)+
geom_errorbar(aes(ymin=emmean-SE, ymax=emmean+SE),
width=0.2,
size=0.75,
position=position_dodge(width=0.9))+
geom_text(position=position_dodge2(width=0.9),vjust=-0.5,size=4)+
theme_classic()+
theme(legend.position = "bottom")
ggsave("Three way anova with cld.png",p, width=9, height=5, units="in")
with theme pubr
p = ggplot(emmean_cld,aes(species,emmean,fill=island,pattern=sex, label=.group))+
geom_col_pattern(alpha=0.5,color="grey20",
position = "dodge",
pattern_fill = "black",
pattern_angle = 45,
pattern_density = 0.1,
pattern_spacing = 0.025,
pattern_key_scale_factor = 0.6)+
#scale_pattern_manual(values = c(Nerd = "stripe", NotNerd = "none"))+
geom_errorbar(aes(ymin=emmean-SE,ymax=emmean+SE),
position = position_dodge(width=0.9), width=0.3,size=0.5)+
geom_text(position = position_dodge2(width=0.9),vjust=-0.5,size=4)+
guides(pattern = guide_legend(override.aes = list(fill = "white")),
fill = guide_legend(override.aes = list(pattern = "none")))+
theme_pubr()
ggsave("AOV_plot.png",p,width=7,height=4,units="in")
Facebook page:
/ rajendrachoureisc
Mail Id:
rajuchoure@gmail.com
youtube playlist:
• R programming tutorials
Great ❤❤
Please give me coding of interactive three way ANOVA
I will be thankful to you
I have data of plant stress physiology
I want
Factor 1 and 2 on x axis and factor 3 on group or fill
Sir why is it showing : "Error in seq.default(from, to, by) : invalid '(to - from)/by'" or "no applicable method for 'depth' applied to an object of class "NULL"' after first ggplot command
Just show me the code. You can copy paste that here . I will try running it.
Thanks for teaching how to use emmeans and cld.
I have used your codes, but following your code following erorrs are noticed:
1. when specs is added to emmeans (emmeans(mod3,specs = c("species","island","sex")) its throwing an error: Error in RG@levels[[f]] : invalid subscript type 'language'.
2. When cld is used (cld(emmean,Letters=letters)) following error is noticed: Error in UseMethod("cld") : no applicable method for 'cld' applied to an object of class "emmGrid"
Please suggest whats going wrong?
I will look into it.
My system is not loading emmeans function. Is there any other way for three-way anova and getting Signif. letters?
Have you installed the packages Bd called the libraries which I mentioned in the script? You can share your script and structure of data. I will try running it.
Don't you test assumptions before doing ANVOVA?
yes we need to. We can validate results after the test also.
@@DevResearch Thank you for your reply and helpful tutorial. Could you have a tutorial on the analysis of 3 factors with non-parametric data? I am looking for the code for a 3-factor nonparametric test and pairwise comparison.
@@myyennguyen7073 Do you want to perform test with formula like response ~ fact1+fact2+fact3 ?
@@DevResearch should be response ~ fact1*fact2*fact3 (both main and interaction effect)
Could you guild me on how to add Compact letter display(CLD) three-way ANOVA and visualization for boxplot? Thank you!