简体   繁体   中英

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

这是我在绘制上面的代码后得到的

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM