Git Product home page Git Product logo

Comments (4)

eliocamp avatar eliocamp commented on August 11, 2024 1

Great! This now should be fixed in the dev version you can install with remotes::install_github("eliocamp/ggnewscale@dev"). Let me know if it works :)

Thanks for the report and the example (I added it as a test).

from ggnewscale.

eliocamp avatar eliocamp commented on August 11, 2024

Thanks. Do you have a reproducible example? ggnewscale is supposed to mimic your solution, but it's possible it needs to do more.

from ggnewscale.

carlschmidt26 avatar carlschmidt26 commented on August 11, 2024

Thanks for the quick reply.
Here is an example which throws the error mentioned above:

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 plyr::ddply() does not make that much sense in this example, however as pointed out earlier, this is the source of the error.

Either applying the solution of the original post or simply calling geom_violin() instead of geom_violin(stat = "ydensity2") works like a charm. plyr::ddply() just isn't happy about the renaming of the variables that takes places due to the call of new_scale_fill().

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 plyr::ddply() in geoms at some point in general.

Looking forward to hearing about your thoughts on this.

from ggnewscale.

carlschmidt26 avatar carlschmidt26 commented on August 11, 2024

Great, thank you very much.
I am quite busy at the moment, but I will give it a try as soon as can in the next days!

Thanks again and all the best!

from ggnewscale.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.