Reputation: 10626
I am working with bunch of different data frames which could have multiple variables or a singel variable:
my data frame looks like this: x
Team Grade
Football 10
When I do this, bar size is huge. I would like to have a fix size so that it looks good when there is one or 2 rows of data:
ggplot(x, aes(Team, Grade, group=Team)) + geom_bar(aes(fill=Team))
Upvotes: 1
Views: 2548
Reputation: 16607
If your data look like this:
df <- data.frame(Team=gl(4, 1), Grade=sample(1:4))
You can specify the width of the bar as follows:
ggplot(df, aes(x=Team, y=Grade, fill=Team)) + geom_bar(width=0.2)
Which gives this plot:
A similar data set, but with only one Team, is given by:
ggplot(subset(df, Team==1), aes(x=Team, y=Grade, fill=Team)) + geom_bar(width=0.2)
Which looks OK, I think.
If you are more concerned about the situation where you only have one Team (or a few), and the bars all go to the top of the plot, you can set y limits:
+ scale_y_continuous(limits=c(0, 4))
Upvotes: 4