Support "ggnewscale" through geom_NewGeomLine etc
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied ggplotly example and tracing the warnings from geom2trace.default for geom_NewGeomLine. Review how ggplotly handles these generated geoms, then determine the required support for the ggnewscale example and verify that it renders without the reported warnings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100