I've been trying to use plot_ly with transforms (ultimately to subset data from a dropdown menu) and a color mapping.
Following is a reproducible example based on mtcars:
transforms without color mapping
If I exclude the color mapping, everything works as expected:
library(plotly)
library(tidyverse)
plot_ly(
data = mtcars %>% rownames_to_column("id"),
x = ~mpg, y = ~disp, text = ~id,
type = "scatter", mode = "markers+text",
marker = list(size = 10, opacity = 0.8),
transforms = list(
list(
type = "filter",
target = ~cyl,
operation = "=",
value = sort(unique(mtcars$cyl))[1])))
Data is filtered for mtcars$cyl values matching sort(unique(mtcars$cyl))[1] = 4. So far so good.
transforms with color mapping
I now like to color-code markers based on the number of carburetors from mtcars$carb; if I add a color mapping, I end up with
library(plotly)
library(tidyverse)
plot_ly(
data = mtcars %>% rownames_to_column("id"),
x = ~mpg, y = ~disp, text = ~id, color = ~as.factor(carb),
type = "scatter", mode = "markers+text",
marker = list(size = 10, opacity = 0.8),
transforms = list(
list(
type = "filter",
target = ~cyl,
operation = "=",
value = sort(unique(mtcars$cyl))[1])))
Somehow, the transforms filter is ignored, as the plot shows entries from mtcars where cyl != 4. I actually don't understand which element plot_ly decides to show here.
Would somebody be able to provide any insight? Many thanks.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)