teunbrand / ggh4x

ggplot extension: options for tailored facets, multiple colourscales and miscellaneous
https://teunbrand.github.io/ggh4x/
Other
542 stars 33 forks source link

not an issue :) #18

Closed tjebo closed 4 years ago

tjebo commented 4 years ago

sorry to leave this as an issue, but it seems the only way to reasonably contact you :)

I thought you'd like this feature I have added to "my" (yours, really) geom_trail Can do text now as well :)

Currently the size is a bit a pain, because I don't know (yet) how to conditionally change the default for size param depending on the "type" argument.

https://github.com/tjebo/ggtrail

https://github.com/tjebo/ggtrail/blob/master/R/geom_trail.R

teunbrand commented 4 years ago

Yeah the text is quite nice, especially when you want to dodge/jitter/position adjust the geom with some randomness.

With regards to the size aesthetic, I'm not sure I'm following 100% what you mean. But you should be able to append some logic to the use_defaults ggproto method.

ggproto(
  "GeomTrail", GeomPoint,
  {...}
  default_aes = aes(size = 1.5, {...}),
  use_defaults = function(self, data, params = list(), modifiers = aes()) {
    size <- data$size # Should be NULL if absent
    new_data <- ggproto_parent(GeomLine, self)$use_defaults(
      data, params, modifiers
    )
    if (is.null(size)) { # Meaning it wasn't there previously --> the default has been set
      if ("label" %in% colnames(new_data)) {
        # Scale to GeomText defaults
        new_data$size <- new_data$size * (3.88/1.5)
      }
    }
    new_data
  }
)