Turning a bar graph into Coxcomb chart

Sreekar

6-7-2023

In this article we will know how to convert bar chart into a coxcomb chart which is a variation of pie chart.

so, first load the package of ggplot2

library("ggplot2")

Then create bar chart named “b”.

b <- ggplot(data=mpg )+geom_bar(mapping = aes(x=class,fill=class),show.legend = F,width = 1)+theme(aspect.ratio = 1)+ labs(x=NULL,y=NULL)

Here we have taken the in built-in data set from ggplot2 which it maps aesthetics on basis of class variable and fills colors with the same.

to display the bar chart type the name of the plot that we have assigned.

b

We use a coord_flip() to flip the x,y coordinates and coord_polar()to turn into coxcomb chart.

b+ coord_flip()
b+coord_polar()