Comments (4)
I have no idea how plotly works, but form what little I've used it, I think it basically hand-crafts translations of each ggplot2 geom to the corresponding plotly mark. If that's the case, then I don't think it'd be possible because the way ggnewscale works is by creating new geoms with new aesthetics for each new scale.
from ggnewscale.
I've skimmed the relevant source code.
For this specific case you can use:
library(ggplot2)
library(ggnewscale)
# Equivalent to melt(volcano)
topography <- expand.grid(x = 1:nrow(volcano),
y = 1:ncol(volcano))
topography$z <- c(volcano)
# point measurements of something at a few locations
set.seed(42)
measurements <- data.frame(x = runif(30, 1, 80),
y = runif(30, 1, 60),
thing = rnorm(30))
# Defines a the to_basic method to the NewGeomContour class and renames the relevant variables.
# Very hacky. Don't know how it will generalise. Will break if you add more scales.
to_basic.NewGeomContour <- function(data, prestats_data, layout, params, p, ...) {
if (!"fill" %in% names(data)) data$fill <- NA
colnames(data)[colnames(data) == "colour_new"] <- "colour"
colnames(data)[colnames(data) == "colour_new_plotlyDomain"] <- "colour_plotlyDomain"
plotly:::prefix_class(data, "GeomPath")
}
ggplot(mapping = aes(x, y)) +
geom_contour(data = topography, aes(z = z, color = stat(level))) +
scale_color_viridis_c(option = "D") +
new_scale_color() +
geom_point(data = measurements, size = 3, aes(color = thing)) +
scale_color_viridis_c(option = "A") -> p
plotly::ggplotly(p)
from ggnewscale.
I have no idea how plotly works, but form what little I've used it, I think it basically hand-crafts translations of each ggplot2 geom to the corresponding plotly mark. If that's the case, then I don't think it'd be possible because the way ggnewscale works is by creating new geoms with new aesthetics for each new scale.
I understand the same as you do, that's why I assumed that it should not be so easy, but just in case I was asking you.
My concern arose from this: ggplotly no me grafica el mismo grafico que ggplot
from ggnewscale.
if (!"fill" %in% names(data)) data$fill <- NA colnames(data)[colnames(data) == "colour_new"] <- "colour" colnames(data)[colnames(data) == "colour_new_plotlyDomain"] <- "colour_plotlyDomain"
I tried something very similar, an automatic wrapper of each new geom to the plotly
function, obviously it solves the warning issue but does not take into account the logic of ggnewscale
.
Thanks for your time Elio
from ggnewscale.
Related Issues (20)
- new scale for x/y? HOT 2
- `override.aes` is ignored with `aesthetics = c("fill", "color")` when using `{ggnewscale}` HOT 2
- Release ggnewscale 0.4.7
- Multiple new_scale_fill doesn't work. HOT 9
- Release ggnewscale 0.4.8
- Issue When Trying to Employ `guide_colourbar` ::::: v0.4.8 HOT 4
- Legend issues when using `guides(...)` HOT 4
- Add ability to name scales HOT 7
- ggnewscale CRAN note HOT 3
- Issues with next version of ggplot2 HOT 4
- Question on overriding scales on a pre-existing ggnewscale plot HOT 3
- Release ggnewscale 0.4.9
- Release ggnewscale 0.4.10
- new_scale_colour does not work with a scale_* function that includes a guide argument HOT 4
- `guide` vs. `show.legend` with `new_scale()` HOT 3
- Does not display two scales HOT 1
- Release ggnewscale 0.5.0
- Release ggnewscale 0.4.10 HOT 4
- new_scale_*() throws an error in ggplot2 3.5.0 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ggnewscale.