0

I have the following type of data (inside a data.frame df):

x     A      B      C
1    100    1.2    1.3
2    90     1.1    0.9

I want to have a multiple bar plot of the columns A, B, C of df, so I run the following:

tmp <- cbind(df$x, melt(df[,-1]))
names(tmp) <- c("x", "variable", "value")
ggplot(tmp, aes(x,value)) + geom_bar(stat = "identity" ) + facet_grid(variable~.)

And it works fine, except for the fact that the values in the column A are much higher than for the rest, and the scales are not adapting. Could somebody give me a hint on own to adjust the scale in each plot?

Thanks a lot!

S4M
  • 4,561
  • 6
  • 37
  • 47
  • 1
    In the future, please include the `library` statements required for your code to run and use `dput` or a more easily reproducible representation of your data. – Justin Jul 30 '13 at 17:24

1 Answers1

2

you need to add scales='free_y' to facet_grid as documented in ?facet_grid...

library(ggplot2)
library(reshape2)

df <- read.data('clipboard', header=TRUE)

tmp <- cbind(df$x, melt(df[, -1]))
names(tmp) <- c("x", "variable", "value")

ggplot(tmp, aes(x=x)) + 
  geom_bar(stat = "identity" ) + 
  facet_grid(variable ~ ., scales='free_y')
Justin
  • 42,475
  • 9
  • 93
  • 111
  • I've tried your answer, but i get this: `Error in exists(name, envir = env, mode = mode) : argument "env" is missing, with no default` – Juan Mar 25 '15 at 18:07
  • Here is the correct answer, as Justin stated at the beginning: ggplot(tmp, aes(x,value)) + geom_bar(stat = "identity" ) + facet_grid(variable~., scales='free_y') – Yu Shen Mar 27 '15 at 09:41