# Polar Coordinates for Better Visualization with ggplot2

Published in

I have been doing some reading and experimenting with data visualization. One of the things that I really liked is the usage of Polar coordinates. This is basically using a grid of circles instead of a grid of straight line like so

from wikipedia

What does this have to do with visualization? It can help you with comparing different values more clearly with better spacing. I will show you an example in R and ggplot2.

Imagine we want to visualize the data of mile consumption of different cars. We can use a simple bar plot like so:

`mtcars\$car = row.names(mtcars)p = ggplot(mtcars, aes(x=car, y=mpg, fill=mpg)) +    geom_bar(binwidth=1, stat=’identity’) +theme_light() +    scale_fill_gradient(low=’red’, high=’white’, limits=c(5,40)) +    theme(axis.title.y=element_text(angle=0))p + theme(axis.text.x = element_text(angle=45, vjust = 1, hjust=1))`

you will get this:

With polar coordinates, you will just use

`p + coord_polar()`

And you will get this more visually pleasing and easier to compare between bars graphics (because of the difference in the value is showed by both the height and the width of the bar at the end).

I first thought that polar coordinates are more of a gimmick, but the more I see/use it, the more I like it. What do you think? Let me know if you saw any good use-cases of the polar coordinate visualization.

A bonus trick

I don’t feel that sorting alphabetically adds any value or makes the graph more interesting than any other sorting. Let’s sort the graph by the actual mpg.

`p + coord_polar() + aes(x=reorder(car, mpg)) +    theme(axis.text.x = element_text(angle=-20)) # text with angle to avoid name overlap`