[英]How to facet a plot_ly() chart?
使用ggplot2
和plotly
使用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)
是否可以使用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
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)
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.