Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stat_contour binwidth oddity

I have some data to display in a facetted levelplot (contour lines), and was very surprised to see strange noisy contour lines in one of the panels where the data were basically constant. I set the binwidth to 1 for the whole layer (all panels), and the subset of the data for this panel was in the range 1 +/- 1e-10, so I expected to see no contour line there. After much subsettting, here is an example of data that shows a contour line, where I wouldn't want/expect to see one.

b = data.frame(energy = rep(c(1,2),5), 
               R = rep(c(1-1e-10, 1), each=5), 
               N = c(55, 55, 65, 65, 75, 75, 85, 85, 95, 95))

ggplot(b)+ 
  geom_line(aes(energy, N, z=R), binwidth=1,
            alpha=0.5, stat="contour")

Why should ggplot2 show a contour line in this region where the data is constant, given that binwidth >> range(b$R)?

enter image description here

Note that binwidth=2 returns a blank panel, and a warning message,

Warning message:
Not possible to generate contour data 

which is perfectly fine, and should also happen at much lower binwidth.

like image 816
baptiste Avatar asked Feb 27 '26 03:02

baptiste


1 Answers

Since it received no answer, I'm posting this issue as a bug report.

like image 130
baptiste Avatar answered Mar 01 '26 17:03

baptiste



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!