1

I have this small dataset

map red_team blue_team
 1     7         8
 2     21        32
 3     11        22
 4     10        8

And I am trying to create a multiplot where each individual plot one represents one of the maps (1,2,3 and 4), and the content is two bars, one for red_team and another for blue_team on the X axis and the score on the Y axis.

This what I currently have.

ggplot(winners_and_score, aes(red_team)) + geom_bar() + facet_wrap(~ map)

I'm having issue trying to display the score for both teams.

Current plot

Thanks.

1
  • 4
    reshape2::melt(winners_and_score, id = "map") will give you a long format data.frame making this easier Commented Jul 20, 2015 at 22:46

1 Answer 1

4
require(reshape2)
require(ggplot2)

# toy data
df = data.frame(map = 1:4, red_team = sample(7:21, 4, replace=T), 
                               blue_team = sample(8:32, 4, replace=T))

df.melted <- melt(df, id='map')

> df.melted
  map  variable value
1   1  red_team     8
2   2  red_team    15
3   3  red_team    17
4   4  red_team    19
5   1 blue_team    22
6   2 blue_team    32
7   3 blue_team    31
8   4 blue_team    18

# making the plot
ggplot(data=df.melted, aes(x=variable, y=value, fill=variable)) + 
       geom_bar(stat='identity') + 
       facet_wrap(~map) + 
       theme_bw()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.