使用ggplot2
和plotly
与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()
...
p<-iris%>%
group_by(Species)%>%
plot_ly(x = ~Sepal.Length, y = ~Sepal.Width, color = ~Species, type = "scatter")%>%
subplot() ##Something else here?
p
答案 0 :(得分:1)
这有效,但感觉像是黑客。
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)
这是格子plot_ly
图表的正确方法吗?
...使用新的dplyr::group_map()
函数进行编辑。
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)