renkun-ken / formattable

Formattable Data Structures
Other
693 stars 79 forks source link

RFC: ggplot2 support #31

Open krlmlr opened 8 years ago

krlmlr commented 8 years ago

Attaching formatting to values is a very neat approach. Any thoughts on making this compatible with ggplot? Example:

data.frame(x=formattable::percent(1:10) / 100, y = 1:10) %>% ggplot(aes(x=x, y=y)) + geom_point()

I would expect the formatting to show up on the axes.

renkun-ken commented 8 years ago

I've considered this indeed but haven't come up with a way to do this even with basic plot. I'll try more.

krlmlr commented 4 years ago

Still not working for me... We can't rely on scale_x_continuous(labels = format), when the labels are computed the class is lost already. I think this has to be fixed at the ggplot2 side?

library(tidyverse)

my_format <- function(x) {
  print(x)
  format(x)
}

data.frame(x = formattable::percent((1:10) / 100), y = 1:10) %>%
  ggplot(aes(x = x, y = y)) %>% 
  + geom_point() %>% 
  + scale_x_continuous(labels = my_format)

#> [1]    NA 0.025 0.050 0.075 0.100

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

renkun-ken commented 4 years ago

Yes, I guess the plot function has to use the format string as the label rather than numeric value, or otherwise I guess I can do nothing about it.

krlmlr commented 4 years ago

Upstream: https://github.com/tidyverse/ggplot2/pull/4065.