I manage to create a dataframe as shown but I dont know how to create faceted pie charts out of it. Can someone show me how? Thanks in advance. enter image description here
Asked
Active
Viewed 61 times
-1
-
Does this answer your question? [faceted piechart with ggplot](https://stackoverflow.com/questions/22592789/faceted-piechart-with-ggplot) – harre Jul 08 '22 at 17:09
1 Answers
0
I am not sure what you want to show, so you could do something like this:
df <- data.frame(rideable_type = c("classic_bike", "classic_bike", "docked_bike", "electric_bike", "electric_bike"),
member_causal = c("causal", "member", "causal", "causal", "member"),
number_of_bikes = c(1313878, 2013712, 308241, 1048194, 1250025),
total = c(2670303, 3263737, 2670303, 2670303, 3263737),
freq = c(49.2, 61.6, 11.5, 39.2, 38.3))
library(ggplot2)
ggplot(df, aes(x = factor(1), fill=factor(rideable_type))) +
facet_wrap(~member_causal) +
geom_bar(width = 1,position = "fill") +
coord_polar(theta="y") +
labs(fill = "rideable type", x = "", y = "")
Created on 2022-07-08 by the reprex package (v2.0.1)

Quinten
- 35,235
- 5
- 20
- 53
-
thanks a lot! i have one more question ^_^ can you show me how to put percentage label on it? – trangha2710 Jul 08 '22 at 17:43