相关疑难解决方法(0)

将星星放在ggplot条形图和箱线图上 - 表示显着性水平(p值)

将星星放在条形图或箱线图上以显示一组或两组之间的显着性水平(p值)是很常见的,下面是几个例子:

在此输入图像描述在此输入图像描述在此输入图像描述

星数由p值定义,例如,p值<0.001时可以放3颗星,p值<0.01时可以放2颗星等等(虽然这会从一篇文章变为另一篇文章).

我的问题:如何生成类似的图表?根据显着性水平自动放置星星的方法非常受欢迎.

r bar-chart ggplot2 boxplot p-value

37
推荐指数
4
解决办法
6万
查看次数

ggplot2 boxplots - 如果没有重要的比较,如何避免额外的垂直空间?

在关于如何制作具有方面和显着性水平的箱形图的许多问题之后,特别是这个这个,我还有一个小问题.

我设法制作了如下所示的情节,这正是我想要的.

我现在面临的问题是,我很少或没有重要的比较; 在这些情况下,专用于显示显着性水平的括号的整个空间仍然保留,但我想摆脱它.

请使用iris数据集检查此MWE:

library(reshape2)
library(ggplot2)
data(iris)
iris$treatment <- rep(c("A","B"), length(iris$Species)/2)
mydf <- melt(iris, measure.vars=names(iris)[1:4])
mydf$treatment <- as.factor(mydf$treatment)
mydf$variable <- factor(mydf$variable, levels=sort(levels(mydf$variable)))
mydf$both <- factor(paste(mydf$treatment, mydf$variable), levels=(unique(paste(mydf$treatment, mydf$variable))))
a <- combn(levels(mydf$both), 2, simplify = FALSE)#this 6 times, for each lipid class
b <- levels(mydf$Species)
CNb <- relist(
    paste(unlist(a), rep(b, each=sum(lengths(a)))), 
    rep.int(a, length(b))
)
CNb
CNb2 <- data.frame(matrix(unlist(CNb), ncol=2, byrow=T))
CNb2
#new p.values
pv.df <- data.frame()
for (gr in unique(mydf$Species)){
    for (i in 1:length(a)){
        tis <- …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

6
推荐指数
1
解决办法
1136
查看次数

R ggplot2:具有wilcoxon显着性水平和构面的箱线图。仅显示与星号的重大比较

为了完整起见,针对这个问题,我修改了可接受的答案并定制了结果图,但我仍然面临一些重要问题。

总而言之,我正在做箱形图,以反映Kruskal-Wallis和成对的Wilcoxon测试比较的重要性。

我想将P值数字替换为星号,并仅显示重要的比较,从而将垂直间距减小到最大值。

基本上,我想做这个,但面的补充问题,即混乱的一切行动。

到目前为止,我已经开发了一个非常不错的MWE,但是它仍然显示出问题...

library(reshape2)
library(ggplot2)
library(gridExtra)
library(tidyverse)
library(data.table)
library(ggsignif)
library(RColorBrewer)

data(iris)
iris$treatment <- rep(c("A","B"), length(iris$Species)/2)
mydf <- melt(iris, measure.vars=names(iris)[1:4])
mydf$treatment <- as.factor(mydf$treatment)
mydf$variable <- factor(mydf$variable, levels=sort(levels(mydf$variable)))
mydf$both <- factor(paste(mydf$treatment, mydf$variable), levels=(unique(paste(mydf$treatment, mydf$variable))))

# Change data to reduce number of statistically significant differences
set.seed(2)
mydf <- mydf %>% mutate(value=rnorm(nrow(mydf)))
##

##FIRST TEST BOTH

#Kruskal-Wallis
addkw <- as.data.frame(mydf %>% group_by(Species) %>%
                       summarize(p.value = kruskal.test(value ~ both)$p.value))
#addkw$p.adjust <- p.adjust(addkw$p.value, "BH")
a <- combn(levels(mydf$both), 2, simplify = …
Run Code Online (Sandbox Code Playgroud)

testing r facet ggplot2 boxplot

5
推荐指数
1
解决办法
2158
查看次数

R ggplot2 - 在一个方面中对每对执行成对测试,并使用 ggsignif 显示 p 值

继我几天前发布的这个问题之后,我想执行类似的操作。

给定以下 MWE:

##############################
##MWE
library(ggplot2)
library(ggsignif)

set.seed(1)
alpha.subA <- data.frame(Sample.ID=paste(sample(LETTERS, 163, replace=TRUE), sample(1:1000, 163, replace=FALSE), sep=''),
                   Group=c(rep('C',10),rep('FH',10),rep('I',19),rep('IF',42),rep('NA',14),rep('NF',42),rep('NI',15),rep('NS',10),rep('PGMC4',1)),
                   Value=rnorm(n=163))
alpha.subA$DB <- "DATABASE1"
set.seed(2)
alpha.subB <- data.frame(Sample.ID=paste(sample(LETTERS, 163, replace=TRUE), sample(1:1000, 163, replace=FALSE), sep=''),
                   Group=c(rep('C',10),rep('FH',10),rep('I',19),rep('IF',42),rep('NA',14),rep('NF',42),rep('NI',15),rep('NS',10),rep('PGMC4',1)),
                   Value=rnorm(n=163))
alpha.subB$DB <- "DATABASE2"
alpha.sub <- rbind(alpha.subA, alpha.subB)

alpha.sub$DB <- as.factor(alpha.sub$DB)
alpha.sub$both <- factor(paste(alpha.sub$Group, alpha.sub$DB), levels=paste(rep(levels(alpha.sub$Group), each=length(levels(alpha.sub$DB))), rep(levels(alpha.sub$DB), length(levels(alpha.sub$Group)))))

png(filename="test.png", height=1000, width=2000)
print(#or ggsave()
  ggplot(alpha.sub, aes(x=both, y=Value, fill=Group)) + geom_boxplot() +
    facet_grid(~Group, scales="free", space="free_x") +
    stat_summary(fun.y=mean, geom="point", shape=5, size=4)

    # + geom_signif() ##HOW TO TEST EACH …
Run Code Online (Sandbox Code Playgroud)

testing r ggplot2 boxplot

4
推荐指数
1
解决办法
4709
查看次数

标签 统计

ggplot2 ×4

r ×4

boxplot ×3

testing ×2

bar-chart ×1

facet ×1

p-value ×1