Question: Boxplot/bargraph for expression data using ggplot2
0
gravatar for krushnach80
4 months ago by
krushnach80170
krushnach80170 wrote:

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 • 278 views
ADD COMMENTlink modified 4 months ago • written 4 months ago by krushnach80170
1

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 REPLYlink written 4 months ago by salamandra70

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

ADD REPLYlink written 4 months ago by krushnach80170

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 REPLYlink written 4 months ago by Devon Ryan73k

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 REPLYlink written 4 months ago by krushnach80170

See the gather() function in tidyr.

ADD REPLYlink written 4 months ago by Devon Ryan73k
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 REPLYlink modified 4 months ago • written 4 months ago by krushnach80170

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 REPLYlink written 4 months ago by jrj.healey2.9k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 692 users visited in the last hour