0

I have a bar chart that shows two soccer teams and their wins and draws vs each other. Then each bar is divided to show the form of the team at the time they played each other.

Is is possible then to divide those sub-divisions to show the proportion of home and away matches for each combination of 'Form team and result'?

This is the chart as it currently exists: enter image description here

What I want to do is, for example, sub-divide the red "Blades and win" block in the left hand bar into 'home' (11) and 'away' (8).

Is that possible?

Do I need a different viz?

Mr_Percy_Heat
  • 59
  • 1
  • 10
  • Please provide sample data and code. [https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example] – Nick Kennedy Feb 20 '19 at 20:59
  • 1
    Could you make your problem reproducible by sharing a sample of your data and the code you're working on so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Feb 21 '19 at 03:27
  • I've been trying for an hour now. I need to create a new column that indicates home or away for each state of form and result. I think I'll have to give up and photoshop it. – Mr_Percy_Heat Feb 21 '19 at 16:26

1 Answers1

0

How is your data set up? I will assume:

df = data.frame("team", "Game_Number", "Result", "Location")

Team = c("Blades", "Blades", "Blades")
Game_Number = c(1, 2, 3) 
Result = c("Win", "Draw", "Loss")
Location = c("Home", "Home", "Away") 

Create a concatenated column:

df$Outcome <- paste(df$Result,"-",df$Location)

Now plot your data using Outcome:

ggplot2.barplot(data=df, xName="Team", groupName="Outcome")

I wrote the code without testing, but it give the idea. You just need to combine the columns. You can keep your naming convention, just concatenate the location with your variable "Form Team and Result".

caszboy
  • 48
  • 1
  • 8