PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, June 28, 2022

[FIXED] Why is the wilcox.test results overlapping when I try to plot a graph?

 June 28, 2022     graph, r, statistics     No comments   

Issue

I'm trying to get statistics on my faceted graph, but the output of the wilcoxon test are overlapped like this:

enter image description here

The code I am using is this:

ggplot(df, aes(y = count, x = time, group = time)) + 
  theme_bw() +
  geom_boxplot()+
  theme(legend.position = "none")+
  scale_y_log10(limits = c(1, 250)) +
  facet_wrap(vars(cluster), scales = "fixed")+
  stat_compare_means(method= "wilcox.test")
 labs(y = "Clone count", x = "Time point")

And my data looks like this:

structure(list(time = c("Day 0", "Day 0", "Day 0", "Day 0", "Day 0", 
"Day 0", "Day 0", "Day 0", "Day 0", "Day 0", "Day 1", "Day 1", 
"Day 1", "Day 1", "Day 1", "Day 1", "Day 1", "Day 1", "Day 1", 
"Day 1", "Day 2", "Day 2", "Day 2", "Day 2", "Day 2", "Day 2", 
"Day 2", "Day 2", "Day 2", "Day 2", "Day 2", "Day 2", "Day 2", 
"Day 2", "Day 2", "Day 2", "Day 2", "Day 2", "Day 2", "Day 2", 
"Day 2", "Day 2", "Day 2", "Day 2", "Day 2"), count = c(1L, 4L, 
1L, 1L, 1L, 1L, 2L, 3L, 1L, 1L, 59L, 1L, 1L, 1L, 3L, 1L, 2L, 
5L, 3L, 1L, 1L, 2L, 1L, 1L, 1L, 54L, 3L, 6L, 1L, 1L, 1L, 2L, 
1L, 1L, 7L, 1L, 3L, 1L, 207L, 5L, 3L, 3L, 11L, 2L, 1L), cluster = c("C", 
"C", "C", "C", "D", "D", "D", "D", "D", "D", "A", "A", "D", "D", 
"D", "C", "C", "C", "C", "C", "D", "D", "D", "D", "D", "B", "C", 
"B", "B", "C", "C", "C", "C", "C", "B", "B", "B", "A", "A", "A", 
"A", "A", "A", "A", "A")), row.names = c(NA, -45L), class = "data.frame")

Also, how would I add significance bars to this?


Solution

It may helps by specifying comparisons.

my_comparisons <- list(c("Day 0", "Day 1"), c("Day 1", "Day 2"), c("Day 0", "Day 2"))
ggplot(df1, aes(y = count, x = time)) + 
  theme_bw() +
  geom_boxplot()+
  theme(legend.position = "none")+
  scale_y_log10() +
  stat_compare_means(method= "wilcox.test", comparisons = my_comparisons)  +
  facet_wrap(.~(cluster), scales = "fixed")+
  labs(y = "Clone count", x = "Time point") +
  ylim(c(0,400))

enter image description here



Answered By - Park
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing