1

I'm trying to create a boxplot, which I've managed to do, but I cannot figure out how to specify the values for error bars. I've already calculated the values in my CSV file (below):

Here's my code:

# ggplot2.boxplot from http://www.sthda.com/english/wiki/easyggplot2?url=/3-easyggplot2/
install.packages("devtools")
library(devtools)
install_github("kassambara/easyGgplot2")

ggplot2.boxplot(data=df, xName='geno', yName='value', groupName='cond',
    groupColors=c('orange','pink'), ytitle="Days", xtitle="Genotype")

And here's what I have: enter image description here


Data:

df <- read.table(
  text = "value   geno    cond    sem
10.33   Control 0       0.1
  10.39   Control 0       0.1
  10.32   Control 0       0.1
  10.58   Control 0       0.1
  13.10   Control 7       0.14
  12.94   Control 7       0.14
  13.38   Control 7       0.14
  13.55   Control 7       0.14
  10.39   Exp1    0       0.03
  10.26   Exp1    0       0.03
  10.38   Exp1    0       0.03
  10.41   Exp1    0       0.03
  14.50   Exp1    7       0.3
  13.00   Exp1    7       0.3
  13.50   Exp1    7       0.3
  13.75   Exp1    7       0.3
  9.74    Exp2    0       0.02
  9.79    Exp2    0       0.02
  9.81    Exp2    0       0.02
  9.83    Exp2    0       0.02
  12.25   Exp2    7       0.13
  11.86   Exp2    7       0.13
  12.50   Exp2    7       0.13
  12.29   Exp2    7       0.13",
  stringsAsFactors = FALSE,
  header = TRUE
)
Re-l
  • 291
  • 1
  • 3
  • 13
  • 1
    what is `ggplot2.boxplot` – Rorschach Jul 03 '15 at 21:23
  • 1
    Oh, sorry. I'm new to R and I thought it was a common package. I got it from here: http://www.sthda.com/english/wiki/ggplot2-boxplot-easy-box-and-whisker-plots-maker-function – Re-l Jul 03 '15 at 21:30
  • 1
    Since the syntax seems to be very similar to that of `ggplot2`, [this post](http://stackoverflow.com/questions/21915286/r-ggplot2-geom-boxplot-with-custom-quantiles) could be useful here. – RHertel Jul 03 '15 at 22:03
  • 2
    I'm not quite clear what you want. Boxplots show the median, interquartile range and some multiple (typically 1.5) times the IQR. They don't usually have error bars. Error bars are more commonly shown on a bar plot which shows the mean and the standard error. e.g. `library(dplyr);df %>% group_by(geno, cond) %>% summarise(Days = mean(value), sem = mean(sem)) %>% ggplot(aes(x = geno, y = Days, fill = factor(cond), ymin = Days - sem, ymax = Days + sem)) %>% + geom_bar(stat = "identity", position = dodge <- position_dodge(width = 0.9)) %>% + geom_errorbar(position = dodge, width = 0.25)` – Nick Kennedy Jul 03 '15 at 22:12
  • 1
    `ggplot2.boxplot` looks like wrapper for `ggplot2` functions, but less flexible; you may well be better off using `ggplot2`. you can customize function used to define whiskers (as RHertel indicates), or build boxplot with `geom_linerange` (`geom_errorbar` for crosshatches) and `geom_crossbar` – tegancp Jul 03 '15 at 22:34
  • Okay, thank you all for your input. I'll play around with ggplot2 and if I can't figure it out, I'll just stick with CI with the boxplot. @NickK Thanks for explaining the difference between the two bars. I'll keep it with CI then. – Re-l Jul 03 '15 at 22:41
  • 1
    @Re-l note it's not CI on a boxplot, it's the inter-quartile range. For your dataset, you've only got 4 data points in each group so a boxplot can be difficult to interpret. – Nick Kennedy Jul 03 '15 at 22:43
  • Ah, got it! I misread your post. And you're right, I'm looking at it now and it doesn't seem like the best way to plot my data. I will look at other ways to represent my data. – Re-l Jul 03 '15 at 22:49

1 Answers1

0

It seems that the package used is a wrapper around ggplot2, so I suppose playing with the geom_errorbar function will get OP what they desire.

hd1
  • 33,938
  • 5
  • 80
  • 91