【问题标题】:How to get subplot to show two ploty plots?如何让子图显示两个情节图?
【发布时间】:2021-04-11 17:59:58
【问题描述】:

我正在尝试使用子图并排生成同一块的两个简单图,但只显示其中一个图。

size = 50000
width = 4
x1 = 0
x2 = width
y1 = 0
y2 = size

p1 <- plot_ly(type='area',mode='none',x = c(x1,x2,x2,x1,x1),width = 500, height = 725,
          y = c(y1,y1,y2,y2,y1),
          fill = 'toself',
          fillcolor = 'rgb(233,87,62)')

x1 = 0
x2 = width
y1 = 0
y2 = size

p2 <- plot_ly(type='area',mode='none',x = c(x1,x2,x2,x1,x1),width = 500, height = 725,
         y = c(y1,y1,y2,y2,y1),
         fill = 'toself',
         fillcolor = 'rgb(233,87,62)')

subplot(p1,p2,nrows=1)

【问题讨论】:

  • 也许你想要type="scatter"

标签: r plotly subplot


【解决方案1】:

要使用 plotly 正确创建面积图,请从散点图开始,然后将模式设置为“线条”。

这里是一个更好的样本数据集的例子:

library(plotly) 
1 <- plot_ly(economics, type='scatter', x = ~date, y = ~uempmed, 
          name = 'Left chart',
          fill = 'tozeroy', 
          mode = 'lines', 
          fillcolor = 'rgb(233,87,62)', 
          line = list(color = 'rgb(233,87,62)'))

p2 <- plot_ly(economics, type='scatter', x = ~date, y = ~unemploy, 
              name = 'Right chart',
              fill = 'tozeroy', mode = 'lines', fillcolor = 'rgb(87,87,62)', 
              line = list(color = 'rgb(87,87,62)'))

subplot(p1, p2,  nrows = 1, margin = 0.05, widths =  c(0.6, 0.4))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-23
    • 1970-01-01
    相关资源
    最近更新 更多