r - 如何刻面 plot_ly() 图表?
问题描述
使用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
解决方案
1:使用and方法刻面plot_ly
图表:do()
subplot()
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
2:使用新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)
推荐阅读
- r - 根据以相同字符开头的列创建新变量
- c# - ListView 元素的代码隐藏工具提示
- opencv - 在透明背景上绘制
- oracle-apex - 单击 Apex 5 中的按钮后如何保存复选框字段的选中状态?
- python - 如何计算 Pandas 数据框中新的“标准化”列?
- css - 如何摆脱 React 中的右边距?
- node.js - URL查询字符串中的连续双斜杠被解析为1个斜杠,NodeJs Express
- php - 如何检查是否已通过 WooCommerce 中的管理员修改了已付款订单
- python - `importlib.reload` 不会替换模块的 `__dict__` 中的对象
- c# - c#datatable用空格替换重复值