-
Notifications
You must be signed in to change notification settings - Fork 18
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
Compatibility with custom geoms #27
Comments
Thanks. Do you have a reproducible example? ggnewscale is supposed to mimic your solution, but it's possible it needs to do more. |
Thanks for the quick reply. library(tidyverse)
library(ggnewscale)
# Manipulate `setup_data()` of `StatYdensity` and store the object as `StatYdensity2`.
StatYdensity2 <- ggproto("StatYdensity2", StatYdensity,
setup_data = function (data, params) {
data <- plyr::ddply(data, c("x", "fill"), within,
# Assign the range of `y` to the newly created column `range`.
assign("range", list(range(y))))
data
})
set.seed(5)
df <- data.frame(
x = floor(runif(100, min=1, max=5)),
y = floor(runif(100, min=1, max=10)),
gender = c("female", "male")[floor(runif(100, min=1, max=3))],
fill = floor(runif(100, min=1, max=5))
)
df %>% ggplot(aes(x, y, fill = gender, group = interaction(x, gender))) +
# Call `geom_violin()` using the manipulated stat `StatYdensity2`.
geom_violin(stat = "ydensity2") +
new_scale_fill() +
geom_point(aes(x, y, fill = fill), shape = 21, inherit.aes = F) Note that the call of Either applying the solution of the original post or simply calling At this point I think it's best to use the solution is already described. I just thought it's not that unusual to use Looking forward to hearing about your thoughts on this. |
Great! This now should be fixed in the dev version you can install with Thanks for the report and the example (I added it as a test). |
Great, thank you very much. Thanks again and all the best! |
Hi,
I really like your package. Your effort is really much appreciated!
However when combining my custom geom (e.g.
geom_mycustom()
) withnew_scale_fill()
I encounter an problem, which I'd like to point out in the followingThe problem is that the
setup_data()
function of the associated stat looks like this:The problem is that the column
fill
becomesfill_new
in the second iteration due tonew_scale_fill()
when the whole plot is built again. This results in the following error:A solution to that is to simply change
setup_data
as follow:Just out of curiosity an because I have a few more places where I use
plyr::ddply()
I was wondering if there might be another way to resolve this problem.Happy to hear from you.
Best regards
The text was updated successfully, but these errors were encountered: