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!

1
  • 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. Commented Jul 30, 2013 at 17:24

1 Answer 1

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')
Sign up to request clarification or add additional context in comments.

2 Comments

I've tried your answer, but i get this: Error in exists(name, envir = env, mode = mode) : argument "env" is missing, with no default
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')

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.