I need two pie-charts side by side with the percentages of Covid19 cases, cured and death for two counties in Germany. One county left and the other one on the right.
So far my code looks like this:
RKI_COVID19 %>%
group_by(Landkreis) %>%
summarise(fraction_active = (sum(AnzahlFall)-sum(AnzahlGenesen))/sum(AnzahlFall),
fraction_cured = sum(AnzahlGenesen)/sum(AnzahlFall),
fraction_death = sum(AnzahlTodesfall)/sum(AnzahlFall)) %>%
subset(Landkreis == "SK Wolfsburg" | Landkreis == "SK Münster") %>%
gather("Type", "Value", -Landkreis) %>% # convert to long format
ggplot(aes(Landkreis, Value, fill = Type)) +
geom_col(position = "dodge") +
geom_bar(stat = "identity", position = position_fill()) +
geom_text(aes(label = round(Value, 2)), size = 3, position = position_fill(vjust = 0.5)) +
facet_wrap(~Landkreis) +
coord_polar("y")
after the subset() I have all values I am interestd in:
Landkreis fraction_active fraction_cured fraction_death
<chr> <dbl> <dbl> <dbl>
1 SK Münster 0.108 0.892 0.0115
2 SK Wolfsburg 0.129 0.871 0.118
By using gather() I convert them in a long format and create two side by side barplots. This works great.
The problem occurs when using facet_wrap() and coord_polar() in the last two lines.
Then my pie-charts look like this:
One small and one donut pie-chart
Any ideas how to create two pie-charts with the same size?
ggplot(aes(2, Value, fill = Type))
for equal size and+ xlim(0.5, 2.5)
to make it a donut. See here – stefan