# Importing the required libraries
library(ggplot2)
library(dplyr)
# creating a data frame
data_frame <- data.frame(subject=c('maths','maths','sst',
'science','sst','hindi','maths',
'sst','science','hindi','sst'),
marks=c(4,5,8,2,15,6,3,7,7,6,3))
# creating a pie chart in order
data_frame %>%
group_by(subject) %>%
summarise(ut_marks= sum(marks)) %>%
mutate(mean_ut=ut_marks/sum(ut_marks)) %>%
ggplot(aes(x="", y= mean_ut,
fill=reorder(subject, ut_marks))) +
geom_col() + geom_text(aes(label = scales::percent(round(mean_ut,2))),
position = position_stack(vjust = 0.5))+
coord_polar(theta = "y")