【问题标题】:plotly multiple plot facet情节多情节方面
【发布时间】:2016-11-29 09:34:20
【问题描述】:

我想像这样在每个图上用两个轴做多图

library(plotly)
ay <- list(
  tickfont = list(color = "green"),
  overlaying = "y",
  side = "right", title = "y2 axis title"
)


par(mfrow=c(2,1))
ax <-list(title = "x axis title")
ay1 <-list(title = "y1 axds title")
plot_ly(x = 1:3, y = 10*(1:3), name = "slope of 10") %>%
  add_trace(x = 2:4, y = 1:3, name = "slope of 1", yaxis = "y2") %>%
  layout(title = "Double Y Axis", yaxis2 = ay, xaxis = ax, yaxis = ay1) 


 ax <-list(title = "x axis title")
 ay1 <-list(title = "y1 axds title")
 plot_ly(x = 1:3, y = 10*(1:3), name = "slope of 10") %>%
   add_trace(x = 2:4, y = 1:3, name = "slope of 1", yaxis = "y2") %>%
   layout(title = "Double Y Axis", yaxis2 = ay, xaxis = ax, yaxis = ay1) 

但是当您运行该代码时,您仍然只能看到一个图。 plotly 可以做多图吗?它可以用两个轴进行刻面吗?

【问题讨论】:

  • 您是否要在同一页面上绘制这 2 个(相同的)图?
  • 是的。我希望他们显示在另一个之上。但理想情况下,我希望能够将 facet_wrap 与 plotly 一起使用。这可能吗?

标签: r ggplot2 plotly r-plotly


【解决方案1】:

您正在寻找subplot。查看此page 了解更多信息

library(plotly)
ay <- list(
    tickfont = list(color = "green"),
    overlaying = "y",
    side = "right", title = "y2 axis title"
)

ax <-list(title = "x axis title")
ay1 <-list(title = "y1 axds title")   

 subplot(
        plot_ly(x = 1:3, y = 10*(1:3), name = "slope of 10") %>%
            add_trace(x = 2:4, y = 1:3, name = "slope of 1", yaxis = "y2") %>%
            layout(title = "Double Y Axis", yaxis2 = ay, xaxis = ax, yaxis = ay1), 
        plot_ly(x = 1:3, y = 10*(1:3), name = "slope of 10") %>%
            add_trace(x = 2:4, y = 1:3, name = "slope of 1", yaxis = "y2") %>%
            layout(title = "Double Y Axis", yaxis2 = ay, xaxis = ax, yaxis = ay1), nrows = 2)

输出

【讨论】:

  • 当我运行上面的代码时,情节没有出现。我还删除了最后一行“ay1”之后的“)”
  • 我发布了运行完全相同的代码时得到的输出。我正在使用plotly_3.6.0ggplot2_2.1.0
  • 试试这个:将您的第一个 plot_ly 图分配给 a,将第二个分配给 b。然后运行subplot(a,b, nrow= 2)。现在剧情出现了吗?
  • @user3022875,您是否正在查看查看器窗格? plotly 绘图不会显示在绘图窗格中
猜你喜欢
  • 2018-03-30
  • 1970-01-01
  • 1970-01-01
  • 2014-05-11
  • 2022-12-06
  • 1970-01-01
  • 2019-10-05
  • 1970-01-01
相关资源
最近更新 更多