Support "ggnewscale" through geom_NewGeomLine etc
There are many use cases where a user wants to split a colour (or any other attribute) scale into multiple components. For example, if two separate types of data are being presented and it doesn't make sense to compare colours between these datasets.
In the example below, I am visualising a time series with time/y coordinates using geom_line, and also known timepoints that have only time coordinates using geom_vline. Note that this renders correctly using ggplot, but results in a blank plot and many errors with ggplotly:
require('dplyr')
#> Loading required package: dplyr
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
require('tidyr')
#> Loading required package: tidyr
require('tibble')
#> Loading required package: tibble
require('ggplot2')
#> Loading required package: ggplot2
require('ggnewscale')
#> Loading required package: ggnewscale
require('plotly')
#> Loading required package: plotly
#>
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#>
#> last_plot
#> The following object is masked from 'package:stats':
#>
#> filter
#> The following object is masked from 'package:graphics':
#>
#> layout
series = rnorm(50*5) %>%
matrix(ncol=5) %>%
as_tibble() %>%
rownames_to_column() %>%
pivot_longer(cols=!rowname)
#> Warning: The `x` argument of `as_tibble.matrix()` must have unique column names if `.name_repair` is omitted as of tibble 2.0.0.
#> Using compatibility `.name_repair`.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_warnings()` to see where this warning was generated.
changepoints = cbind(
x=sample(x=1:50, size=8, replace=T),
name=sample(x=c('a', 'b'), size=8, replace=T)
) %>%
as_tibble()
plt = ggplot() +
geom_line(data=series, aes(x=rowname, y=value, color=name, group=name)) +
new_scale_color() +
geom_vline(data=changepoints, aes(xintercept=x, color=name), size=1.5)
print(plt)

print(ggplotly(plt))
#> Warning in geom2trace.default(dots[[1L]][[5L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_NewGeomLine() has yet to be implemented in plotly.
#> If you'd like to see this geom implemented,
#> Please open an issue with your example code at
#> https://github.com/ropensci/plotly/issues
#> Warning in geom2trace.default(dots[[1L]][[5L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_NewGeomLine() has yet to be implemented in plotly.
#> If you'd like to see this geom implemented,
#> Please open an issue with your example code at
#> https://github.com/ropensci/plotly/issues
#> Warning in geom2trace.default(dots[[1L]][[5L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_NewGeomLine() has yet to be implemented in plotly.
#> If you'd like to see this geom implemented,
#> Please open an issue with your example code at
#> https://github.com/ropensci/plotly/issues
#> Warning in geom2trace.default(dots[[1L]][[5L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_NewGeomLine() has yet to be implemented in plotly.
#> If you'd like to see this geom implemented,
#> Please open an issue with your example code at
#> https://github.com/ropensci/plotly/issues
#> Warning in geom2trace.default(dots[[1L]][[5L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_NewGeomLine() has yet to be implemented in plotly.
#> If you'd like to see this geom implemented,
#> Please open an issue with your example code at
#> https://github.com/ropensci/plotly/issues
Created on 2021-02-12 by the reprex package (v1.0.0)
Ideally the entire package ggnewscale would be supported in ggplotly. Internally it seems to use functions such as geom_NewGeomLine, and these are the functions that plotly would need to implement to get this to work.
Same problem here. Need ggnewscale.
I would also love to see this implemented. I have a plot I'm trying to get into plotly that has three layers of geom_tile overlaid and get geom_NewGeomTile() has yet to be implemented in plotly. followed by geom_NewNewGeomTile() has yet to be implemented in plotly. followed by geom_NewNewGeomTile() has yet to be implemented in plotly.
E.g.,
library(plotly)
library(ggnewscale)
foo <- data.frame(x=1:10,y=1:10)
foo$oddOne <- factor(foo$y %% 2)
p1 <- ggplot(foo) +
geom_tile(aes(x=0,y=y,fill=oddOne),
width=Inf,height=1,show.legend = FALSE) +
scale_fill_manual(values = c("darkblue", "darkgreen")) +
new_scale_fill() +
geom_tile(aes(x=x,y=y),width=1,height=0.5,fill="grey") +
new_scale_fill() +
geom_tile(aes(x=x,y=y),width=0.5,height=0.25,fill="white") +
theme_minimal()
p1
ggplotly(p1)
Warning messages:
1: In geom2trace.default(dots[[1L]][[2L]], dots[[2L]][[1L]], dots[[3L]][[1L]]) :
geom_NewNewGeomTile() has yet to be implemented in plotly.
If you'd like to see this geom implemented,
Please open an issue with your example code at
https://github.com/ropensci/plotly/issues
2: In geom2trace.default(dots[[1L]][[2L]], dots[[2L]][[1L]], dots[[3L]][[1L]]) :
geom_NewNewGeomTile() has yet to be implemented in plotly.
If you'd like to see this geom implemented,
Please open an issue with your example code at
https://github.com/ropensci/plotly/issues
3: In geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]) :
geom_NewGeomTile() has yet to be implemented in plotly.
If you'd like to see this geom implemented,
Please open an issue with your example code at
https://github.com/ropensci/plotly/issues