小编Dan*_*Cee的帖子

R ggplot2箱图-ggpubr stat_compare_means无法正常工作

我试图显着性水平加入到我的箱线图中使用星号形式GGPLOT2ggpubr包,但我有很多的比较,我只想展现显著的。

我尝试在stat_compare_means中使用选项hide.ns = TRUE,但显然不起作用,这可能是ggpubr软件包中的错误。

此外,您还可以从成对的wilcox.test比较中忽略 “ PGMC4”组;我怎样才能把这个小组也留给kruskal.test呢?

我有的最后一个问题是重要性水平如何工作?如*显着低于0.05,**低于0.025,***低于0.01?ggpubr使用的约定是什么?它显示的是p值还是调整后的p值?如果是后者,调整方法是什么?BH?

请在下面查看我的MWE,此链接以及其他链接以供参考

##############################
##MWE
set.seed(5)
#test df
mydf <- data.frame(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))
#I don't want to compare PGMC4 cause I have only onw sample
groups <- as.character(unique(mydf$Group[which(mydf$Group!="PGMC4")]))
#function to make combinations of groups without repeating pairs, and avoiding self-combinations
expand.grid.unique <- function(x, y, …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 boxplot p-value ggpubr

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

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
查看次数

ggplot2:绘制2个变量(线和点)并对齐2个图

我最近开始使用ggplot2但是我发现了很多困难......此时我只想将2个不同的变量绘制成一个带点和线的图(类型=两者都在绘图函数中),并得到这个结果图在共享相同x轴的直方图上方放置并对齐.

所以我有这个data.frame:

GO.df <- data.frame(GO.ID=paste("GO",c(1:29),sep=""),
                    occ=c(1:29),
                    pv=c(5.379594e-05, 3.052953e-03, 3.052953e-03, 3.052953e-03, 3.052953e-03, 3.052953e-03, 3.052953e-03, 3.052953e-03, 6.096906e-03, 6.096906e-03, 6.096906e-03, 6.096906e-03, 9.131884e-03, 9.131884e-03, 9.131884e-03, 9.131884e-03, 9.131884e-03, 9.131884e-03, 9.131884e-03, 1.215791e-02, 1.215791e-02, 1.215791e-02, 1.517502e-02, 1.517502e-02, 1.517502e-02, 1.517502e-02, 1.818323e-02, 1.818323e-02, 1.818323e-02),
                    adj.pv=c(0.004088492, 0.029003053, 0.029003053, 0.029003053, 0.029003053, 0.029003053, 0.029003053, 0.029003053, 0.036527537, 0.036527537, 0.036527537, 0.036527537, 0.036527537, 0.036527537, 0.036527537, 0.036527537, 0.036527537, 0.036527537, 0.036527537, 0.042000065, 0.042000065, 0.042000065, 0.044357749, 0.044357749, 0.044357749, 0.044357749, 0.047652596, 0.047652596, 0.047652596))
Run Code Online (Sandbox Code Playgroud)

并想重现这个:

plot(GO.df$pv, type="b", col="red", ylim=c(0,0.05),ylab="",xlab="",xaxt="n")
lines(GO.df$adj.pv, type="b", col="blue")
axis(1, at=c(1:length(GO.df$GO.ID)), labels=GO.df$GO.ID, las=2)
Run Code Online (Sandbox Code Playgroud)

在直方图上方(变量"occ")并与之对齐.这是我到目前为止ggplot2:

#install.packages("ggplot2")
library(ggplot2)
#install.packages("reshape") …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

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

ggplot2:在不同的方面使用不同的颜色

我有一个似乎是一个非常基本的问题,但我无法解决它,因为我几乎没有使用过 ggplots2 ...我只想左边的图使用变量 color1 中的颜色,右边的图使用变量 color1 中的颜色变量 color2 中的颜色。这是一个 MWE:

library(reshape2)
library(ggplot2)

a.df <- data.frame(
  id=c("a","b","c","d","e","f","g","h"), 
  var1=c(1,2,3,4,5,6,7,8), var2=c(21,22,23,24,25,26,27,28), 
  var3=c(56,57,58,59,60,61,62,63), 
  color1=c(1,2,"NONE","NONE",1,2,2,1), 
  color2=c(1,"NONE",1,1,2,2,"NONE",2)
)

a.dfm <- melt(a.df, measure.vars=c("var2","var3"))

ggplot(a.dfm, aes(x=value, y=var1, color=color1)) + 
  geom_point(shape=1) + 
  facet_grid(. ~ variable)
Run Code Online (Sandbox Code Playgroud)

多谢!

r ggplot2

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

CRAN/Bioconductor包安装失败:错误:行开始'<!DOCTYPE HTML PUBLI ...'格式错误

我刚刚安装了一个新的Ubuntu 14.04并按照此链接另一个的说明安装了R ,就像我一直选择伯克利镜像一样.

在emacs(+ ess)上,我根本无法安装任何CRAN或Bioconductor包,例如:

install.packages("ggplot2")
Run Code Online (Sandbox Code Playgroud)

要么:

source("http://bioconductor.org/biocLite.R")
biocLite("biomaRt")
Run Code Online (Sandbox Code Playgroud)

我不断收到以下错误:

Error: Line starting '<!DOCTYPE HTML PUBLI ...' is malformed!
Run Code Online (Sandbox Code Playgroud)

这个其他线程之后,我只是等着看问题是否自己解决了,但是在2天后我一直得到同样的错误.有什么建议??

installation redirect r package cran

4
推荐指数
2
解决办法
5160
查看次数

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
查看次数

R: Reliable conversion between gtable and ggplot objects. How to make lemon::reposition_legend() work after ggplot_build()?

I have a pretty complicated case at hand with ggplot2. I tried to exemplify it with a MWE using iris data below.

I just have boxplots in facets, and wanted to move the legend to take the space of the empty facets.

This is all good, I use lemon::reposition_legend() for that and it works.

However, I then have to modify a bunch of things in the plot (namely add significant test results and other things that are not relevant …

r legend facet ggplot2 r-lemon

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

awk:更改字段分隔符,保持第一列不变

我有一个in.csv只有一列的文件以这种方式:

Sample
a_b_c
d_e_f
g_h_i
Run Code Online (Sandbox Code Playgroud)

我想将字段分隔符从 to 更改_,并打印单独的字段,但将输入列保持在输出文件的第一列中。我想awk原则上使用。

这是我到目前为止:

awk 'BEGIN {FS="_";OFS=","} {$1=$1}1' in.csv > out.csv
Run Code Online (Sandbox Code Playgroud)

这给了我这个

Sample
a,b,c
d,e,f
g,h,i
Run Code Online (Sandbox Code Playgroud)

我怎样才能像这样输出它,保留原始列(重命名ID)?

ID,group1,group2,group3
a_b_c,a,b,c
d_e_f,d,e,f
g_h_i,g,h,i
Run Code Online (Sandbox Code Playgroud)

请注意,输入的字段数是可变的,输入Sample行可能是其他名称,或者为空,甚至不存在,但我仍然希望这样的输出......

编辑

检查所有答案后,我必须在这里澄清上面的输入文件只是一个例子......我的真实文件通常有超过3个字段_(但我事先不知道有多少)和无数行分隔,但是我将尝试确保给定文件中的所有行在要“拆分”的字段数上保持一致。

当我的文件每行要拆分的字段多于或少于 3 个时,下面的答案似乎不起作用,如果可能的话,我需要一个更通用的单行。

目前,为了简单起见,我宁愿不对标题行做任何事情并保持原样。

这意味着对于另一个示例:

Some_header
a_b_c_1
d_e_f_2
g_h_i_3
Run Code Online (Sandbox Code Playgroud)

我想获得这个:

Some_header
a_b_c_1,a,b,c,1
d_e_f_2,d,e,f,2
g_h_i_3,g,h,i,3
Run Code Online (Sandbox Code Playgroud)

最佳情况下,单行应该处理存在字段不一致的行的情况,因此从这样的文件中:

Some_header
a_b_c
d_e_f_2
g_h_i_3_4
Run Code Online (Sandbox Code Playgroud)

我想获得这个:

Some_header
a_b_c,a,b,c
d_e_f_2,d,e,f,2
g_h_i_3_4,g,h,i,3,4
Run Code Online (Sandbox Code Playgroud)

有没有办法用_in 变量记录行,然后将变量拆分为_,然后打印变量及其所有组件,并由 分隔,?对不起,我认为这会更容易……也许单线会更容易Perl?对不起,对单线不够精通……再次感谢!

regex awk field

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

R:ggplot2 - 每个方面的 Kruskal-Wallis 测试

我有多个方面的箱线图,我想在每个方面执行 Kruskal-Wallis 测试,并将结果放在每个相应方面的左上角。

为了举例说明这一点,我使用了 iris 数据集,并向其中添加了一个名为“treatment”的附加变量。

微量元素:

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)))

ggplot(mydf,aes(x=variable, y=value)) +
    geom_boxplot(aes(fill=Species)) +
    facet_grid(treatment~Species, scales="free", space="free_x") +
    geom_text(label=paste("Kruskal-Wallis, p=", with(mydf, kruskal.test(value ~ variable)$p.value)))
Run Code Online (Sandbox Code Playgroud)

以上是我最好的尝试,它产生了以下结果。

测试

这显然是错误的。

我希望跨度量(Petal.Length、Petal.Width、Sepal.Length、Sepal.Width)的 Kruskal-Wallis 测试结果显示在每个面的左上角。

每个数据子集应该执行 6 次测试(根据处理和物种),所以我猜应该调整 p.value(最好由 Benjamini-Hochberg 调整)。

如果可能的话,如果每个结果 p.value 可以四舍五入到小数点后两位,那就太好了。如果可能的话,我宁愿避免使用 ggpubr,因为我在使用它时遇到问题,并坚持使用 geom_text()。谢谢!

testing r facet ggplot2

3
推荐指数
1
解决办法
2507
查看次数

R XLConnect:loadWorkbook 警告 - “发生了非法反射访问操作”

我正在使用 XLConnect 读取 R(版本 3.4.4)中的 xlsx 文件,但收到以下警告。我认为它们可能与Java有关,但我不是Java用户,我不知道如何让它们消失。谢谢!

MWE 与任何 xlsx 文件:

library(XLConnect)
infile <- 'any.xlsx'
wb <- loadWorkbook(infile)
mydf <- readWorksheet(wb, sheet=1, region='A1:AS91', header=TRUE, check.names=FALSE, useCachedValues=TRUE)
Run Code Online (Sandbox Code Playgroud)

警告:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.poi.openxml4j.util.ZipSecureFile$1 (file:/usr/local/lib/R/site-library/XLConnect/java/poi-ooxml-3.17.jar) to field java.io.FilterInputStream.in
WARNING: Please consider reporting this to the maintainers of org.apache.poi.openxml4j.util.ZipSecureFile$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Run Code Online (Sandbox Code Playgroud)

java warnings r xlsx

3
推荐指数
1
解决办法
4936
查看次数

标签 统计

r ×9

ggplot2 ×7

boxplot ×3

facet ×3

testing ×3

awk ×1

cran ×1

field ×1

ggpubr ×1

installation ×1

java ×1

legend ×1

p-value ×1

package ×1

r-lemon ×1

redirect ×1

regex ×1

warnings ×1

xlsx ×1