如何通过相应的tukey测试在箱图中订购变量

问题描述 投票:0回答:1

我使用了来自r-graph-gallery.com的代码,该代码适合我的数据。

我想在一个图形中做6个箱形图,并以特定的顺序对其进行排序,但是在进行排序时,tukey分析不会同时对其进行排序!

您知道我该如何改善吗?

这是错误的顺序,但正确的tukey测试表示形式:“图形顺序错误”

这里是顺序正确但tukey测试分区不正确的一个。“图形错误的图基测试位置”“ >>

我还应该怎么做才能为TUKEY测试获得正确的顺序?

通过这种方式,没有人知道如何获得tukey测试最高平均值的“ a”值而不是“ c”的值吗?

谢谢您的帮助!

这是我使用的代码:

date<- (read.delim("SoilOBIoldtd.txt", header=TRUE))
# library
library(multcompView)
# What is the effect of the level on the CEC ?
model=lm( date$CEC_eff ~ date$level )

ANOVA=aov(model)
# Tukey test to study each pair of level :
TUKEY <- TukeyHSD(x=ANOVA, 'date$level', conf.level=0.95)
#This line is the difference between the two plots (using or ignoring this line)
date$level <- factor(date$level , levels=c("DAFS_Top", "DAFS_Down",
"CONV_Top","CONV_Down","Old_cocoa_Top","Old_cocoa_Down"))
# Tuckey test representation :
plot(TUKEY , las=1 , col="brown")
generate_label_df <- function(TUKEY, CEC_eff){
   # Extract labels and factor levels from Tukey post-hoc 
  Tukey.levels <- TUKEY[[CEC_eff]][,4]
  Tukey.labels <- data.frame(multcompLetters(Tukey.levels,reversed = FALSE)['Letters'])
  #I need to put the labels in the same order as in the boxplot :
  Tukey.labels$level=rownames(Tukey.labels)
  Tukey.labels=Tukey.labels[order(Tukey.labels$level) , ]
  return(Tukey.labels)}
# Apply the function on my dataset
LABELS <- generate_label_df(TUKEY , "date$level")
# A panel of colors to draw each group with the same color :
my_colors <- c(   rgb(143,199,74,maxColorValue = 255),  rgb(242,104,34,maxColorValue = 255),   rgb(111,145,202,maxColorValue = 255))
# Draw the basic boxplot
a <-boxplot(date$CEC_eff ~ date$level , ylim=c(min(date$CEC_eff ) , 1.1*max(date$CEC_eff)) , col=my_colors[as.numeric(LABELS[,1])] , ylab="CEC" , main="")
# I want to write the letter over each box. Over is how high I want to write it.
over <- 0.1*max( a$stats[nrow(a$stats),] )
#Add the labels
text( c(1:nlevels(date$level)) , a$stats[nrow(a$stats),]+over , LABELS[,1]  , col=my_colors[as.numeric(LABELS[,1])] )

我使用了来自r-graph-gallery.com的代码,该代码适合我的数据。我想在一张图中做6个箱形图,并按照特定的顺序对其进行排序,但是当我进行排序时,tukey ...

r position boxplot tukey
1个回答
0
投票

嘿,我想我遇到了您的问题,基本上是将彩色/文本标签正确分配给箱线图。

© www.soinside.com 2019 - 2024. All rights reserved.