rtukey

Tukey test only plot significant mean differences


I tried to use the following code from a previous post: Tukey Graphing Problems in R

SigOnly <- Tukey 
SigOnly$species <- SigOnly$species[SigOnly$species[,'p adj'] < .05, ]
plot(SigOnly)

But get the following error when trying to plot:

Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ

What could I be doing wrong?


Solution

  • Since you don't provide reproducible code with sample data, here is an example using the warpbreaks sample data:

    fm1 <- aov(breaks ~ wool + tension, data = warpbreaks)
    res <- TukeyHSD(fm1, "tension", conf.level = 0.95)
    
    # Filter rows with padj < 0.05
    res$tension <- res$tension[res$tension[, 4] < 0.05, ];
    
    # Plot results
    plot(res);
    

    enter image description here