Skip to content

Example of stat_bin2d with a log-scaled axis #1118

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
wants to merge 1 commit into from

Conversation

tgs
Copy link
Contributor

@tgs tgs commented Jun 10, 2015

I couldn't find an example of this anywhere, and it took me an hour to figure out, so I thought maybe it belonged in the documentation. I'm not sure if anyone else is trying to do this, though.

Here's the image that the added example generates:

semilog

And here's the current help page: http://docs.ggplot2.org/current/stat_bin2d.html

I couldn't find an example of this anywhere, and it took me an hour to figure out, so I thought maybe it belonged in the documentation. I'm not sure if anyone else is trying to do this, though.
@hadley
Copy link
Member

hadley commented Jun 11, 2015

Why not just use scale_y_log10() ?

@tgs
Copy link
Contributor Author

tgs commented Jun 12, 2015

You're right, this doesn't make sense on its own. The issue I had is that I wanted to set explicit breaks for one dimension (x axis as date binned by month), and so I had to also set the breaks for the other dimension, because stat_bin2d requires that both dimensions of breaks be supplied the same way. So you have to say stat_bin2d(breaks=list(x = xbreaks, y = ybreaks)). I could have avoided the whole issue if I could have said stat_bin2d(breaks = list(x = xbreaks, y = NA)), and had it generate its default breaks for the y axis. Maybe I should throw out this documentation patch, and write that functionality patch instead.

Or is there some other way I should have made the graph in the first place?

    x_edges <- as.numeric(seq(floor_date(x_range[1], 'month'),
                              ceiling_date(x_range[2], 'month'), by="month"))

    y_edges <- seq(log10(y_range[1] * 0.95),
                   log10(y_range[2] * 1.05), length.out=30)

    (ggplot(data)
     + aes(...)
     + scale_y_log10()
     + stat_bin2d(breaks=list(x = x_edges, y = y_edges)))

@tgs
Copy link
Contributor Author

tgs commented Jun 14, 2015

Take a look at #1126 instead?

@tgs tgs closed this Jun 14, 2015
@lock
Copy link

lock bot commented Jan 19, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants