How to create Polar Charts

5

In this post I am going to show how to create a polar chart using R codes inside Power BI.

imagin that we have below dataset about 4 main groups and their related values.

1

I am going to show you how to draw different polar charts with different shapes.

imagin that we have a bar chart created from below codes, first, I am using “ggplo2” package for this aim.Next, in aes function , x axis will have the group name, y axis will have the value of each group, and the fill color has the group name. then I used geom_bar function to draw a simple bar chart

library(ggplot2)
ggplot(dataset, aes(x = Group, y = Value ,fill = Group )) + 
  geom_bar(width = 0.85, stat="identity")

the result of running the code in Power BI is below chart:

2

Now, I am going to change the chart into a simple polar chart, first based on Y axis value then based on x axis value.

y-axis polar chart

library(ggplot2)
ggplot(dataset, aes(x = Group, y = Value ,fill = Group )) + 
  geom_bar(width = 0.85, stat="identity")+coord_polar(theta = "y")

 

I just add a layer to the above furmula “coord_polar()” this function also has been used for creating pie charts. it gets the “theta” variable, in below example I put theta=y axis, so we have below charts

3

 

X- axis Value

I able also to change the theta varibale to x axis to have a chart based on x,

I wrote below codes

library(ggplot2)
ggplot(dataset, aes(x = Group, y = Value ,fill = Group )) + 
  geom_bar(width = 0.85, stat="identity")+coord_polar(theta = "x")

the result of runig the above code would be below chart, as you see the bar chart has been change to a polar bar chart.

4

Redffrence :http://ggplot2.tidyverse.org/reference/coord_polar.html

Leila Etaati on LinkedinLeila Etaati on TwitterLeila Etaati on Youtube
Leila Etaati
Trainer, Consultant, Mentor
Leila is the first Microsoft AI MVP in New Zealand and Australia, She has Ph.D. in Information System from the University Of Auckland. She is the Co-director and data scientist in RADACAD Company with more than 100 clients in around the world. She is the co-organizer of Microsoft Business Intelligence and Power BI Use group (meetup) in Auckland with more than 1200 members, She is the co-organizer of three main conferences in Auckland: SQL Saturday Auckland (2015 till now) with more than 400 registrations, Difinity (2017 till now) with more than 200 registrations and Global AI Bootcamp 2018. She is a Data Scientist, BI Consultant, Trainer, and Speaker. She is a well-known International Speakers to many conferences such as Microsoft ignite, SQL pass, Data Platform Summit, SQL Saturday, Power BI world Tour and so forth in Europe, USA, Asia, Australia, and New Zealand. She has over ten years’ experience working with databases and software systems. She was involved in many large-scale projects for big-sized companies. She also AI and Data Platform Microsoft MVP. Leila is an active Technical Microsoft AI blogger for RADACAD.

Leave a Reply