小编Rfr*_*eak的帖子

R 中子图plot_ly 中每个图附近的图例

我使用plotly 中的subplot 函数在我的R-shiny 应用程序中绘制两个图表(一个在另一个下)。图例对于这两个图来说都很常见,这意味着我只有一列将所有图例组合在一起。

我想在子图中将每个图表附近的图例分开。我怎样才能获得它?

p1 <-
 iris%>%
 group_by(Species)%>%
 plot_ly(x=~Sepal.Length, color= ~Species, legendgroup=~Species)%>%
 add_markers(y= ~Sepal.Width)
p2 <-
 iris%>%
 group_by(Species)%>%
 plot_ly(x=~Sepal.Length, color= ~Species, legendgroup=~Species)%>%
 add_markers(y= ~Sepal.Width)

 subplot(p1,p2, nrows = 2, shareX = T, shareY = F, titleX = T, titleY = T)
Run Code Online (Sandbox Code Playgroud)

上面代码的结果

我想要的布局如下: 想要的结果

r subplot plotly

5
推荐指数
1
解决办法
3308
查看次数

标签 统计

plotly ×1

r ×1

subplot ×1