New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stat_binhex, stat_summary_hex, and ggplot2's bins are out of kilter #1383

Closed
AmagicalFishy opened this Issue Oct 21, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@AmagicalFishy

AmagicalFishy commented Oct 21, 2015

library(ggplot2)
dat <- data.frame(x = rnorm(100000, 0, 5), y = rnorm(100000, 0, 5), z = rnorm(100000, 42, 42))

hexHist = ggplot(dat, aes(x, y, z = z)) + 
    stat_binhex(bins = 10) +
    stat_summary_hex(aes(label=..value..), bins = 10,
                     fun = function(z) {
                         (round(sum(z)/length(z), 0))
                     },
                     geom = "text")

histexample

And, if we look at the bin centers of ggplot_build():

hexDat = ggplot_build(hexHist)$data[[1]] 
hexHist2 = hexHist + annotate("text", hexDat$x, hexDat$y, label = "o")

histexample2

I've been told that some tiles that are supposed to be there aren't being plotted.

@hadley

This comment has been minimized.

Member

hadley commented Nov 9, 2015

Simpler reprex:

set.seed(12)
n <- 1e4
dat <- data.frame(x = rnorm(n, 0, 5), y = rnorm(n, 0, 5))

ggplot(dat, aes(x, y, z = x)) + 
  stat_binhex(bins = 10) +
  stat_summary_hex(bins = 10, fun = length,  geom = "point", colour = "red")

Not only are points misaligned, some coloured cells don't have red points and vice versa.

@hadley hadley added this to the v1.0.0 milestone Nov 9, 2015

@hadley hadley added the bug label Nov 9, 2015

@hadley hadley modified the milestones: v2.0.1, v1.0.0 Dec 15, 2015

@hadley

This comment has been minimized.

Member

hadley commented Feb 4, 2016

Even simpler, and calibrated with geom_point(): suggests that the bug is in stat_summary_hex():

set.seed(12)
n <- 1e2
dat <- data.frame(x = rnorm(n, 0, 5), y = rnorm(n, 0, 5))

ggplot(dat, aes(x, y, z = x)) + 
  stat_binhex(bins = 10) + 
  geom_point(colour = "white") + 
  guides(fill = "legend")

ggplot(dat, aes(x, y, z = x)) + 
  stat_binhex(bins = 10) +
  stat_summary_hex(bins = 10, fun = length,  geom = "point", colour = "red")

@hadley hadley closed this in f7cb898 Feb 4, 2016

@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.