如何刻画 plot_ly() 图表? [英] How to facet a plot_ly() chart?
本文介绍了如何刻画 plot_ly() 图表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 ggplot2
和 plotly
制作带有 facet_wrap()
的交互式散点图.
Using ggplot2
and plotly
to make an interactive scatter plot with facet_wrap()
.
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()
函数切面"?文档建议 subplot()
...
Is it possible to "facet" using the plot_ly()
function? The documentation suggests 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()<对
plot_ly
图表进行分面/code> 方法:
1: Facet a plot_ly
chart using the do()
and subplot()
method:
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()
函数将 plot_ly
图表网格化.
2: Trellis a plot_ly
chart using the new dplyr::group_map()
function.
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)
这篇关于如何刻画 plot_ly() 图表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文