Making a Polar Histogram in Ggplot2

I am trying to make a polar histogram out of the code below, but the histogram looks pretty ugly after it is plotted.

My dataframe looks like this

> dist <-data.frame(dtPTT)
> head(dist)
 dtPTT
 1 64462.139
 2  9967.527
 3  2021.063
 4  1452.435
 5  1287.067
 6  1601.852

And this is the code I used

ggplot(dist, aes(x = dtPTT)) +
  geom_histogram(binwidth = 5) +
  scale_x_continuous(breaks = seq(0, 360, 60)) +
  coord_polar() +
  xlab(NULL)+ylab(NULL)

This is what I am getting after plotting the code above

3

1 Answer

I think the culprit is your binwidth. Using the same syntax as you, but with iris, we get a "pretty" histogram:

ggplot(iris, aes(x = Sepal.Width)) +
  geom_histogram(binwidth = .1) +
  scale_x_continuous(breaks = seq(0, 360, 60)) +
  coord_polar() +
  xlab(NULL)+ylab(NULL)

given that in dist, dtPTT is 64462 in the first entry and the binwith from your histogram appears to go to 240k, I think ggplot is just getting overwhelmed by all the empty bins. Try starting with binwidth 1000 and experiment from there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest