'ggploting multiple columns in one bar graph which are grouped by a 4th column
I have a data frame that takes the format below (couldn't do it any better), with game sales from 3 regions grouped by gerne, i would like to ggplot them in a bar graph, where for example the Action genre would be in the x axis and 3 bars for the 3 regions are represented by their values in y axis , and so on.sample desired result
Genre : Action,Sport,Fighting,Platform
NA : 10, 13, 3, 5
EU : 7, 11, 1, 3
JP : 8, 10, 2, 9
Solution 1:[1]
library(tidyverse)
tribble(
~Region, ~Action, ~Sport, ~Fighting, ~Platform,
NA, 10L, 13L, 3L, 5L,
"EU", 7L, 11L, 1L, 3L,
"JP", 8L, 10L, 2L, 9L
) %>%
pivot_longer(-Region) %>%
ggplot(aes(name, value, fill = Region)) +
geom_col(position = "dodge")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jon Spring |

