Skip to content
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

Default scales for non-standad computed aes. #4291

Closed
eliocamp opened this issue Dec 8, 2020 · 2 comments
Closed

Default scales for non-standad computed aes. #4291

eliocamp opened this issue Dec 8, 2020 · 2 comments

Comments

@eliocamp
Copy link
Contributor

eliocamp commented Dec 8, 2020

metR's geom_vector/geom_arrow can draw arrows based either on dx and dy or magnitude and angle. If the user supplies dx and dy, then mag is a computed aesthetic. The package also has a scale_mag_continuous() with it's own guide. ggplot2 adds the relevant scale if the mag aesthetic is supplied by the user, but not if it's computed by the stat:

library(metR) 
library(ggplot2)
data(seals)
ggplot(seals, aes(long, lat)) +
    geom_vector(aes(mag = sqrt(delta_long^2 + delta_lat^2), angle = atan2(delta_lat, delta_long)*180/pi)) 

   
ggplot(seals, aes(long, lat)) +
    geom_vector(aes(dx = delta_long, dy = delta_lat))

Created on 2020-12-08 by the reprex package (v0.3.0)

What should I do so that scale_mag_continuous() is added automatically even when the mag aesthetic is computed?

@thomasp85
Copy link
Member

I don't think that is possible currently 😔

Maybe the best would be to provide a simple helper function, e.g. magnitude <- function(dx, dy) sqrt(dx^2 + dy^2) and remove that calculation from the stat. If you do that then the last example would become:

ggplot(seals, aes(long, lat)) +
    geom_vector(aes(mag = magnitude(delta_long, delta_lat)))

and everything should work...

That being said I understand your request but I fear it will be long before we can support it (if at all)

@eliocamp
Copy link
Contributor Author

Oh, ok. That's a bummer. I'll see what I can do, then. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants