'(CLOSED) Generating faceted pie charts to indicate weightages
I am looking to build a visual with multiple pie charts to showcase different sleeping conditions and their weightage across a week.
Here's my dataset:
structure(list(Date = structure(c(1L, 2L, 4L, 5L, 6L, 8L, 9L,
10L, 12L, 13L, 14L, 15L, 17L, 18L, 19L, 20L, 21L, 22L, 24L, 25L
), .Label = c("4/12/2016", "4/13/2016", "4/14/2016", "4/15/2016",
"4/16/2016", "4/17/2016", "4/18/2016", "4/19/2016", "4/20/2016",
"4/21/2016", "4/22/2016", "4/23/2016", "4/24/2016", "4/25/2016",
"4/26/2016", "4/27/2016", "4/28/2016", "4/29/2016", "4/30/2016",
"5/1/2016", "5/2/2016", "5/3/2016", "5/4/2016", "5/5/2016", "5/6/2016",
"5/7/2016", "5/8/2016", "5/9/2016", "5/10/2016", "5/11/2016",
"5/12/2016"), class = "factor"), DayOfWeek = structure(c(3L,
4L, 6L, 7L, 1L, 3L, 4L, 5L, 7L, 1L, 2L, 3L, 5L, 6L, 7L, 1L, 2L,
3L, 5L, 6L), .Label = c("Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"), class = "factor"), Condition = structure(c(2L,
3L, 3L, 3L, 2L, 2L, 2L, 3L, 3L, 2L, 3L, 3L, 3L, 2L, 3L, 3L, 3L,
3L, 2L, 3L), .Label = c("Fast Sleepers", "Average Sleepers",
"Potentially Insomnia"), class = "factor")), row.names = c(NA,
-20L), class = c("tbl_df", "tbl", "data.frame"))
I am looking to achieve something like this where I can:
- Illustrate the weightage between the three conditions
- Split the data (via Facet) down to 7 days (Sunday to Saturday)
- Label each portion in the chart with their respective percentages
But with my code below:
ggplot(mod_sleep_day, aes(x= Condition, fill=Condition)) + #scale_y_continuous(labels=percent) +
geom_bar(width = 1) +
scale_fill_manual(values=c("#459ba8", "#79c267", "#f28c33")) +
coord_polar("y", start = 0) +
facet_wrap(~DayOfWeek) +
labs(title = "Weightage of sleeping conditions") +
theme(axis.text=element_text(size=20), axis.title=element_text(size=20,face="bold"),
title=element_text(size=30,face="bold"), legend.title=element_text(size=14),
legend.text=element_text(size=13), strip.text.x = element_text(size = 20),
axis.title.x = element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank()) +
scale_fill_manual(values=c("#f9d6c1", "#e39676", "#ab354c", "#3f0236"))
I am achieving something like this instead. I know it's far from my ideal output but I've spent quite a long time troubleshooting this and this is the closest I could get.
I am sorry if the images don't load up automatically. I am still very new in SO.
Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|