繁体   English   中英

如何刻面 plot_ly() 图表?

[英]How to facet a plot_ly() chart?

使用ggplot2plotly使用facet_wrap()制作交互式散点图 plot 。

library(ggplot2)
library(plotly)

g<-iris%>%
  ggplot(aes(x = Sepal.Length, y = Sepal.Width, color = Species))+
  geom_point()+
  facet_wrap(vars(Species))
ggplotly(g)

带有 facet_wrap 的 ggplot2 散点图,以 plotly 呈现

是否可以使用plot_ly() function “刻面”? 文档建议subplot() ...

p<-iris%>%
  group_by(Species)%>%
  plot_ly(x = ~Sepal.Length, y = ~Sepal.Width, color = ~Species, type = "scatter")%>%
  subplot() ##Something else here? 
p

如何刻面这个 plot_ly 散点图?

1:使用do()和 subplot subplot()方法对plot_ly图表进行刻面:

library(plotly)
iris%>%
  group_by(Species) %>%
  do(p=plot_ly(., x = ~Sepal.Length, y = ~Sepal.Width, color = ~Species, type = "scatter")) %>%
  subplot(nrows = 1, shareX = TRUE, shareY = TRUE)

使用 group_by() 和 do() 函数制作的 Plot_ly 图表

2:使用新的dplyr::group_map() function 绘制一个plot_ly图表。

library(dplyr)
iris%>%
  group_by(Species) %>%
  group_map(~ plot_ly(data=., x = ~Sepal.Length, y = ~Sepal.Width, color = ~Species, type = "scatter", mode="markers"), keep=TRUE) %>%
  subplot(nrows = 1, shareX = TRUE, shareY=TRUE)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM