I want to make a simple pie chart but all the labels are pointing to the wrong segment. They labels seem to be mirrored or might have a faulty ypos. I understand that ypos means the position of the labels on the outline of the pie chart, but is there any way that I can mirror the labels in the graph?
RNA <- Final_Vaccine %>%
filter(Vaccine_Tech == "RNA") %>%
group_by(Pathogen) %>%
summarise(Count = n()) %>%
ungroup()
RNA <- RNA %>%
mutate(Percent = Count / sum(Count) * 100,
ypos = cumsum(Percent) - 0.5 * Percent)
The table then looks like this:
(https://i.sstatic.net/lGBjLmW9.png)
ggplot(RNA, aes(x = "", y = Percent, fill = Pathogen)) +
geom_bar(stat = "identity", width = 1) +
coord_polar(theta = "y") +
geom_label_repel(aes(y = ypos, label = paste0(round(Percent, 1), "%")),
nudge_x = 1, nudge_y = 0, size = 4, show.legend = FALSE) +
theme_void() +
scale_fill_brewer(palette = "Pastel2") +
labs(title = "RNA Vaccines pathogens")
Pie Chart looks like this:
(https://i.sstatic.net/TvbuTbJj.png)
I have tried modifying the ypos, putting minus signs. If there are any solutions to recifying the ypos or making the labels point to the correct segment, I would be very grateful.
David Kim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.