0
votes

I try to plot some data using standard graphics of R and ggplot2. First I have a DF with 15 column. So I decide to using the reshape package and to melt the data. I use this code.

require(reshape)
melta <- melt(alc, id.vars = c("SERIAL"))
boxplot(alc = melta,  variable~value)

But I stumble on this error

"Error in eval(expr, envir, enclos) : object 'variable' not found".

Where I made a mistake?

The structure of melta is.

'data.frame':   17108 obs. of  3 variables:
$ SERIAL: int  38029154 38043671 38090011 38092911 38096206 38097725 38098892 38098895 38098986 38099056 ...
$ variable: Factor w/ 14 levels "ALL_CATEGORIES_TOTAL",..: 1 1 1 1 1 1 1 1 1 1 ...
$ value   : num  662866 1404542 889061 1203516 736608 ...

NULL

1
What's the structure (str(melta))? - Roman Luštrik
Hm. Shouldn’t it be boxplot(variable ~ value, data = melta), or, rather, (given your data structure) boxplot(value ~ variable, data = melta)? - Konrad Rudolph
Maybe i should convert serial from int to num? - jjjjjjj jjjjjjj

1 Answers

1
votes

Try this,

boxplot(data = melta,  value~variable)

Whit ggplot:

library(ggplot2)
p <- ggplot(melta, aes(factor(variable), value))
p + geom_boxplot(aes(fill = factor(variable))) +
   facet_wrap( ~ variable, scale="free")+ labs(title = "EC region")+
  scale_fill_discrete(guide=FALSE)