Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

r - With plotly, how to force two plots to have same scales for marker sizes and colors?

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"
  )

enter image description here

enter image description here

question from:https://stackoverflow.com/questions/65929159/with-plotly-how-to-force-two-plots-to-have-same-scales-for-marker-sizes-and-col

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...