简体   繁体   English

R图:子图仅显示底部图

[英]R-plotly: Subplot shows only bottom plot

I would like to reproduce the "Scaled Subplots" in https://plot.ly/r/subplots/ for the mtcars data. 我想在mtcars数据的https://plot.ly/r/subplots/中复制“ Scaled Subplots”。

mtcars %>%
  transform(id = as.integer(factor(am))) %>%
  plot_ly(x = ~mpg, y = ~qsec, color = ~factor(vs), yaxis = ~paste0("y", id)) %>%
  add_markers() %>%
  subplot(nrows = 2, shareX = TRUE)

Only the bottom subplot shows up: 仅显示底部子图: 生成的图像缺少子图

I thought that I did faithfully copy/translated the code, but something must be wrong. 我以为我确实忠实地复制/翻译了代码,但是一定有问题。 Of note, the subplot discriminates am , whereas the color discriminates vs . 值得注意的是,子图区分am ,而颜色区分vs I tried am for both the subplot and the color: 我试图am的次要情节和颜色都:

mtcars %>%
  transform(id = as.integer(factor(am))) %>%
  plot_ly(x = ~mpg, y = ~qsec, color = ~am, yaxis = ~paste0("y", id)) %>%
  add_markers() %>%
  subplot(nrows = 2, shareX = TRUE)

It does not help much, but the two grids appear: 它并没有多大帮助,但是出现了两个网格: 缺少数据的其他图像 On the latter example, I expected the am==0 (blueish) dots to be in the top subplot. 在后一个示例中,我期望am==0 (蓝色)点位于顶部子图中。

Any suggestion? 有什么建议吗?

packageVersion('plotly')
[1] ‘4.9.0’

Well, this way here you can do this, but must create two plots and than use subplot() 好吧,在这里您可以这样做,但是必须创建两个图,然后使用subplot()

p1 = mtcars %>%
      filter(am==0) %>%
      plot_ly(x = ~mpg, y = ~qsec, color = ~vs, legendgroup = "am0", name = "0",
          type = "scatter" , mode = "markers", showlegend = FALSE)

p2 = mtcars %>%
      filter(am==1) %>%
      plot_ly(x = ~mpg, y = ~qsec, color = ~vs, legendgroup = "am1", name = "1",
          type = "scatter" , mode = "markers")

subplot(p1,p2,nrows = 2, shareX = TRUE, titleY = TRUE, which_layout = 1)

Here the output: 这里的输出:

情节

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM