I am using plotly to make scatter plots with marker color and size mapping to two variables in mtcars
dataset: mtcars$hp
is mapped to colors and mtcars$disp
is mapped to sizes of markers. The plots generated from the following codes have the yellow markers in p1
with mtcars$hp ≈ 180
and in p2
with mtcars$hp ≈ 350
. If I want to compare these side by side, how can I make the plots to have a same color scale?
Similarly, how to map he sizes of the marker on the same size scale?
p1 <- mtcars %>%
filter(cyl == 6) %>%
plot_ly(
x = ~wt, y = ~mpg, color = ~hp, size = ~disp,
type = "scatter", mode = "markers"
)
p2 <- mtcars %>%
filter(cyl == 8) %>%
plot_ly(
x = ~wt, y = ~mpg, color = ~hp, size = ~disp,
type = "scatter", mode = "markers"
)
question from:
https://stackoverflow.com/questions/65929159/with-plotly-how-to-force-two-plots-to-have-same-scales-for-marker-sizes-and-col 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…