[R] how to add count to pie chart legend
Ana Marija
@okov|c@@n@m@r|j@ @end|ng |rom gm@||@com
Mon Aug 15 17:52:01 CEST 2022
Hi All,
I have df like this:
> df# A tibble: 2 × 4
V1 n perc labels
<chr> <int> <dbl> <chr> 1 Yes 8 0.364 36% 2 No 14 0.636 64%
I am making pie chart like this:
library(ggplot2)
ggplot(df, aes(x = "", y = perc, fill = V1)) +
geom_col(color = "black") +
geom_label(aes(label = labels),
position = position_stack(vjust = 0.5),
show.legend = FALSE) +
guides(fill = guide_legend(title = "Answer")) +
coord_polar(theta = "y") +
theme_void()
How would I add in the legend beside Answer "Yes" count 8 (just number
8) and beside "No" count 14?
Thanks
Ana
[[alternative HTML version deleted]]
More information about the R-help
mailing list