Boxplot/bargraph for expression data using ggplot2
0
0
Entering edit mode
6.8 years ago
1769mkc ★ 1.2k

My data frame

gene    WT            ATRA                VD3
INO80   -1.522663774    0             -0.7068400406
CHD2    1.5314010666    -1.9582412148 -0.1891538235
CHD7    1.1916322634    0              2.0417385999
HELLS   4.804731294     0             -0.0810994075

. I would like to put std.deviation and std.error of mean in my final bar graph

I want to plot my expression data as such

Any help or suggestion would be highly appreciated

R • 3.2k views
ADD COMMENT
1
Entering edit mode

to do the error bars more than one value per condition is needed follows just the code for the barplots:

a <- data.frame(WT=c(-1.522663774, 1.5314010666, 1.1916322634, 4.804731294), ATRA=c(0, -1.9582412148, 0, 0), VD3=c(-0.7068400406, -0.1891538235, 2.0417385999, -0.0810994075), stringsAsFactors = F)
row.names(a) <- c("INO80", "CHD2", "CHD7", "HELLS")
a <- t(a)
barplot(a, names.arg=colnames(a), beside=T, legend.text = T)
ADD REPLY
0
Entering edit mode

yes it worked thanks a lot.Can you show me whats wrong with my code if I try that in ggplot2?

ADD REPLY
0
Entering edit mode

It's difficult to interpret what your actual problem is. If you need to add error bars in ggplot2, then it's the geom_errorbar() function.

ADD REPLY
0
Entering edit mode

okay now i have edited my question since I had issues with CHD2 gene .

My issues is I would like to plot the expression of 4 gene in WT ,in ATRA and VD3. So basically i have to melt and reshape the data and plot bar graph that;'s it?

ADD REPLY
0
Entering edit mode

See the gather() function in tidyr.

ADD REPLY
0
Entering edit mode
library(tidyr)
library(dplyr)
library(ggplot2)
dat <- read.csv('gene_boxplot.csv')
head(dat)
mdat = dat%>% gather(key = sample, value = val, -gene)
head(mdat)
 gene      sample        val


 INO80    WT -1.5226638
 CHD2     WT  1.5314011
 CHD7     WT  1.1916323


  HELLS     WT  4.8047313
  SMARCD3   WT -0.5394756


  INO80   ATRA  0.0000000






p <-ggplot(mdat, aes(gene, val))
p +geom_bar()

I get this error Error: stat_count() must not be used with a y aesthetic.

ADD REPLY
0
Entering edit mode

This isn't really a bioinformatics question. This is just that you need to go and follow a walkthrough/tutorial online for how to format the data for ggplot barplots (I'd be the first to admit that ggplot's errors aren't the most discernable).

ADD REPLY

Login before adding your answer.

Traffic: 3120 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