Question: Add error bars to barplot that uses melted dataframe in R
gravatar for j.lunger18
3 months ago by
j.lunger1810 wrote:

I'm attempting to add error bars to my barchart. In order to plot it, I had to melt my dataframe, which originally contained a "plus" column and a "minus" column, which indicated the top and bottom of my error bars respectively for that group of replicates. I don't know how to add in my error bars once my dataframe is melted...

ddCT_results = original data frame

> colnames(ddCT_results)
 [1] "Cell Type"   "Construst"   "Version"     "Target"      "Day"         "Target Name"
 [7] "Ct Mean"     "Ct SD"       "Reference"   "dCt"         "dCt SD"      "ddCt"       
[13] "Fold Change" "Plus"        "Minus"      

> ddCT_results_melted_fc <- melt(ddCT_results, id.vars = c("Version", "Target", "Day"), 
+                                measure.vars = c("Fold Change"))

> colnames(ddCT_results_melted_fc)
[1] "Version"  "Target"   "Day"      "variable" "value"   

> myPlot <- ggplot(ddCT_results_melted_fc, aes(x = Day, y = value, group = Target, fill = Target)) +
+     geom_bar(position = "dodge", stat="identity") +
+     facet_grid(cols = vars(Version), labeller = "label_both") +
+     scale_fill_manual(values = c("#9ecae1", "#3182bd", "#1c9099", "#bdbdbd")) +
+     theme_minimal()

> myPlot

Plot looks great aside from the fact that it doesn't have error bars.

qpcr ddct ggplot2 R • 110 views
ADD COMMENTlink written 3 months ago by j.lunger1810

try geom_errorbar j.lunger18

ADD REPLYlink written 3 months ago by cpad011212k

have a look at this link:, it may help!

ADD REPLYlink written 3 months ago by gabrit90
Please log in to add an answer.


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