Created
April 25, 2020 06:17
-
-
Save rishisidhu/ed1fd0564fb88af436cdc1a4bff1b1a5 to your computer and use it in GitHub Desktop.
An example of how to cluster and stack bars in a bar plot by different variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dummy_data_1 <- tribble( | |
~Country, ~"Time", ~"Score", ~"Gender", | |
"INDIA", "AM", 20, "male", | |
"INDIA", "PM", 20, "female", | |
"INDIA", "AM", 50, "male", | |
"INDIA", "PM", 40, "male", | |
"INDIA", "AM", 20, "female", | |
"USA", "AM", 30, "male", | |
"USA", "PM", 30, "male", | |
"USA", "PM", 30, "female", | |
"USA", "AM", 35, "female", | |
"Canada", "PM", 10, "female", | |
"Canada", "PM", 10, "female", | |
"Canada", "AM", 20, "female", | |
"Canada", "AM", 30, "male", | |
) | |
p <- ggplot(dummy_data_1, aes(x = Time, y = Score, fill = Gender)) + | |
geom_bar(position = "stack", stat = "identity") + | |
facet_wrap( ~ Country) | |
print(p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment