0

I have a dataset for which I am trying to generate grouped boxplots. The y-axis should be the values, x the type of events and then the boxplots will be grouped into when the values were taken (either 24hrs prior to event or on admission).

What I've done thus far is read the data to 'data' and then

data.m <- melt(data)
p <- ggplot(data.m, aes(factor(Type), Value)) + geom_boxplot(aes(fill = Time))

This is what I'm getting.

enter image description here

I'm not sure what I'm doing wrong, any help greatly appreciated.

jazzurro
  • 23,179
  • 35
  • 66
  • 76
xukm
  • 1
  • 1
  • 1
    Your `value` is factor now. You want to convert it to numeric. `ggplot(data.m, aes(factor(Type), as.numeric(Value))) + geom_boxplot(aes(fill = Time))` – jazzurro Feb 05 '15 at 04:58
  • Note that will turn all your "MISS", "?" and "" values to NA (missing). Make sure that's what you want. – MrFlick Feb 05 '15 at 04:59
  • 1
    @jazzurro: factor to numeric conversion does not work the way you appear to believe. See [here](http://stackoverflow.com/questions/3418128/how-to-convert-a-factor-to-an-integer-numeric-without-a-loss-of-information) for more information. Use `as.numeric(as.character(Value))` or `as.numeric(levels(Value))[Value]` instead. – shadow Feb 05 '15 at 10:11
  • @shadow Ah thanks for that. Yes, I learned this from Gregor the other day, and I forgot the lesson. Thank you very much. :) – jazzurro Feb 05 '15 at 10:19

0 Answers0