Skip to content

geom_hex no longer recognizes ..density.. in 2.1.0 #1608

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

Closed
whao89 opened this issue Apr 10, 2016 · 4 comments
Closed

geom_hex no longer recognizes ..density.. in 2.1.0 #1608

whao89 opened this issue Apr 10, 2016 · 4 comments
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@whao89
Copy link

whao89 commented Apr 10, 2016

In 2.1.0:

DF <- data.frame(x=rnorm(1000), y=rnorm(1000))
ggplot(DF) + geom_hex(aes(x=x, y=y, fill=..density..))

causes error:

Error in eval(expr, envir, enclos) : object 'density' not found

But in 2.0.0 (or other older versions), we get (random seeds notwithstanding):

rplot01

@mikebirdgeneau
Copy link

I'm also running into this issue; it looks to be related to changes to the file R/stat-binhex.r in commit f7cb898

The previous code used to return:

# Convert to data frame
  data.frame(
    hexbin::hcell2xy(hb),
    count = hb@count,
    density = hb@count / sum(hb@count, na.rm = TRUE)
  )

whereas it now calls: hexBinSummarise() which ends up returning the results of hexbin::hcell2xy().

I'm not sure what the most elegant fix for this is to allow the previous functionality to remain.

@martinschmelzer
Copy link

I really like to have the old functionality back as well. Especially if you work with large samples and you want to plot gradient plots for all observations hexagon binning with alpha=..count.. was very useful! :)

@mikebirdgeneau
Copy link

mikebirdgeneau commented May 28, 2016

This commit fixes it: https://github.com/mikebirdgeneau/ggplot2/commit/cf990038ffd66983a1ad2760f51c73049dcf56da

I'm not familiar with the reasons behind the change made by Hadley above, so I'm apprehensive to submit a pull request until I understand the implications.

I basically just added back these lines when preparing the data.frame output in hexBinSummarize():

out$count = as.vector(hb@count)
out$density = as.vector(hb@count / sum(hb@count, na.rm = TRUE))

@hadley
Copy link
Member

hadley commented Jul 28, 2016

@mikebirdgeneau looks like just an accidental omission. Can you please subset a PR?

@hadley hadley added bug an unexpected problem or unintended behavior ready labels Jul 28, 2016
@hadley hadley added this to the v2.2.0 milestone Jul 28, 2016
@hadley hadley closed this as completed in 56e2dad Aug 5, 2016
@hadley hadley removed the ready label Aug 5, 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.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants