Barplot of 4 groups with p-val in R
0
0
Entering edit mode
2.6 years ago
ve9 ▴ 50

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 • 1.6k views
ADD COMMENT
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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 
> 
ADD REPLY
1
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 2046 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6