Problem with histogram bar at upper limit of x axis in polar coordinates

40 views
Skip to first unread message

Hefin Rhys

unread,
Nov 18, 2016, 2:15:23 PM11/18/16
to ggplot2
Hi all,

I'm trying to create a rosette plot in ggplot2 as shown below. My x axis breaks are 0, 30, 60, 90 and 120 which wraps around to 0, it is sensible conceptually to the experiment that this is how the axis is broken up. Onto this plotting space I am plotting histograms of my data using geom_histogram(). The problem that I'm having is that the bar for the data binned at the upper limit of my x axis is not drawn properly, only the left edge of the bar is drawn. The code below should reproduce the problem exactly. Playing around with the bin width is able to remove the problem, but isn't desirable. Can you explain why this is happening and what I can do to mitigate it?

Many thanks
Hefin

library(ggplot2)

myData
<- data.frame(c(49,  56,  57,  60,  63,  68,  70,  70,  71,  74,  74,  75,  75,  75,  76,  76,  78,  79,  79,  
 
80,  81,  81,  81,  82,  84,  84,  86,  88,  88,  88,  88,  88,  88,  89,  89,  89,  90,  90,  
 
90,  91,  92,  92,  92,  93,  95,  95,  95,  96,  98,  98,  98,  98,  99,  99, 100, 100, 100,
 
100, 100, 100, 100, 100, 101, 101, 101, 101, 101, 101, 101, 101, 102, 102, 102, 102, 102, 103,
 
104, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 106, 106, 106, 106, 106, 107, 107,
 
107, 108, 108, 108, 108, 108, 108, 108, 108, 109, 109, 110, 110, 110, 110, 111, 111, 111, 111,
 
111, 112, 112, 114, 114, 115, 115, 115, 116, 118, 118, 118, 118, 119, 119, 119, 119, 119, 120,
 
120, 120))

ggplot
(data = myData, aes(x = myData)) +
  coord_polar
() +
  geom_vline
(xintercept = c(0, 30, 60, 90)) +
  scale_x_continuous
(breaks = c(120, 30, 60, 90), limits = c(0,120), labels = c("0", "30", "60", "90")) +
  geom_histogram
(binwidth = 6, colour = "black", size = 0.1)


Tom Hopper

unread,
Dec 6, 2016, 4:31:15 PM12/6/16
to Hefin Rhys, ggplot2
Hefin,

When I remove coord_polar(), I find that there is no bin corresponding to that line. You have the two tall bars (near 30 counts), then the shorter (near 10) and that’s it. It kind of looks like an artifact of the right edge of the bar.

It’s been a long time since I created windrose plots, but I seem to recall having problems with geom_histogram(). I have some code for a 360º windrose that works without drawing artifacts, but it uses geom_bar() instead of geom_histogram(), and scale_x_discrete() instead of scale_x_continuous(). I have to bin the data manually.

Regards,

Tom

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages