如何让子图显示两个情节图?
How to get subplot to show two ploty plots?
我正在尝试使用子图并排生成同一块的两个简单图,但只显示了其中一个图。
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)
要使用 plotly 正确创建面积图,请从散点图开始,然后将模式设置为“线”。
下面是一个更好的示例数据集示例:
library(plotly)
p1 <- 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))
我正在尝试使用子图并排生成同一块的两个简单图,但只显示了其中一个图。
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)
要使用 plotly 正确创建面积图,请从散点图开始,然后将模式设置为“线”。
下面是一个更好的示例数据集示例:
library(plotly)
p1 <- 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))