Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

ggplot2 - R show level significance in grouped barplot

I am searching for a way to calculate and plot significance of certain levels within a grouped barplot in R using ggplot and ggpubr. There is some information available, but non of them seems to work for that special issue. The base data appear to be an aggregation table which looks like that:

survey1 <- as.data.frame(replicate(3,sample(0:1,4,rep=TRUE)))
survey1$V1 <- runif(4)
survey1$V1 <- survey1$V1/sum(survey1$V1)
survey1$V2 <- "survey1"
survey1$V3 <- 1:4
survey1$variable <- "F2500"
colnames(survey1)[1] <- "percent"
colnames(survey1)[2] <- "survey"
colnames(survey1)[3] <- "level"

survey2 <- as.data.frame(replicate(3,sample(0:1,4,rep=TRUE)))
survey2$V1 <- runif(4)
survey2$V1 <- survey2$V1/sum(survey2$V1)
survey2$V2 <- "survey2"
survey2$V3 <- 1:4
survey2$variable <- "F2500"
colnames(survey2)[1] <- "percent"
colnames(survey2)[2] <- "survey"
colnames(survey2)[3] <- "level"

sum.tab <- rbind(survey1, survey2) 

My approach to plot this variable was the following:

library(ggpubr)
library(ggplot2)
ggbarplot(sum.tab, x = "level", y = "percent", fill = "survey", color = NA,
          position = position_dodge2(preserve = "single", padding = 0)) +
          stat_compare_means(aes(group = survey), label = "p.format")

However, it shows a result, but it doesn't seem right. I am searching for an approach to run several dozen variables with a similar plot code within a function...but I am not right there, yet.

examlary plot

Sorry, if I have overseen prior posts regarding that issue (maybe I didn't understand them enough).

Thanks for your help!

question from:https://stackoverflow.com/questions/65849029/r-show-level-significance-in-grouped-barplot

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...