This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Barplot of 4 groups with p-val in R

Dear all,

as I'm new to datastructures in R I'm a bit struggling how to make a boxplot of 4 groups I have with compareson and p-values between them. My data looks like this: LINK and my control group is P in the data.

I'm trying to do something like this, to indicate p-values with *

LINK

pvalue barplot r

You can split the data by group to produce the boxplots. There are several ways to do this, I usually use split() as I've shown here, but other ways are also mentioned in the answers there.

To add the asterisks for p-values I suspect there might be a geom for this in ggplot2, but I haven't done it yet, so either someone else will chip in or I will try to look it up later. Ggplot2 is the library used to produce your example plot. There is a very good introduction on youtube.

Thanks, I got the example picture from here LINK, but I never succseeded in how to import my data with this code even in the first figure as the data seems to have different format.

The data are in MS Excel-style CSV format, you can read it with:

dat <- read.table("file.txt", header=TRUE, sep=";", dec=",")

After that you can use the dat object for further analysis.

You can use dput() on the data object and then paste the output into the post. That saves you from using pastebin.

The OP was unable to import the data, so exporting with dput would not work :)

I have manahe to do some progress, but the result is strange.....I cant tell where I'm wrong in general?

data <- read_delim("data.csv", delim = ";", 
                   escape_double = FALSE, trim_ws = TRUE)


myplot <- ggplot(data, aes(x = group, y = log2FC, fill=group)) + geom_boxplot() + ggtitle("Expr.") + theme(text=element_text(size = 16))

cmpr <- list(c("P","hCG+7"), c("P","hCG+9"))
myplot + stat_compare_means(comparisons = cmpr, tip.length=0.01,
                            label = "p.signif", 
                            symnum.args = list(cutpoints = c(0, 0.0001, 0.001, 0.01, 0.05, 1), 
                                               symbols = c("****", "***", "**", "*", "ns")))

I got this: plot

And warning:

Warning messages:
1: In wilcox.test.default(c(1L, 1L, 1L, 1L, 1L), c(15L, 14L, 10L, 11L,  :
  cannot compute exact p-value with ties
2: Computation failed in `stat_signif()`:
non-numeric argument to binary operator 
> 

Oh I found my data have comma in numbers and it should be dot, silly cross country and Excel formats....

0 answers

No answers yet.

Log in to answer this question.