I would like to be able to make a "Pie chart" in R with ggplot2 but counting the occurrences that a certain data appears.
In my example, I have an Excel from which I extract a column and the values that appear in the columns, for example the column called "discipline" has the values:
discipline1, discipline2, discipline3, discipline1, discipline1, discipline2,
discipline2, discipline2, discipline2, discipline2, discipline3, discipline3.
So what I want to paint is the % of times each of the values appears:
discipline1, discipline2, discipline3
using a Pie Chart.
For the bar chart I used the value stat="count"
, but I have seen that in the Pie Chart I can't.
For example, I tried something like this :
ggplot(df, aes(x = "", y = as.factor(df[,discipline]),
fill = as.factor(df[,discipline]))) +
geom_bar(width = 1, stat = "identity", color = "white") +
coord_polar("y", start = 0)+
geom_text(aes(y = as.factor(df[,discipline]),
label = as.factor(df[,discipline])), color = "white")+
scale_fill_manual(values =c("#0073C2FF", "#EFC000FF", "#868686FF"))+
theme_void()