我使用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)