我已经使用PLOTLY包在R中创建了一系列3D散点图,其中每个图根据我数据集中的不同变量进行着色.我已经设法使用plotly中的subploy()函数或ManipulateWidget包中的combineWidget()函数将它们组合成一个"主"图.有关使用mtars数据集的代表性示例,请参见下面的代码:
#Packages
library(dplyr)
library(plotly)
library("manipulateWidget")
#Dataset
library(datasets)
data(mtcars)
#Four different 3d scatter plots
fig_1 <- plot_ly(mtcars, type = "scatter3d", x = ~mpg, y = ~cyl, z = ~ wt, color = ~as.factor(vs),
colors = c("black", "grey"), scene = "scene",
mode = "markers", marker = list(size = 5, symbol = "circle"))
fig_2 <- plot_ly(mtcars, type = "scatter3d", x = ~mpg, y = ~cyl, z = ~ wt, color = ~as.factor(am),
colors = c("red", "blue"), scene = "scene2",
mode = "markers", marker = list(size = 5, symbol = "circle"))
fig_3 <- plot_ly(mtcars, type = "scatter3d", x = ~mpg, y = ~cyl, z = ~ wt, color = ~as.factor(gear),
colors = c("yellow", "brown", "orange"), scene = "scene3",
mode = "markers", marker = list(size = 5, symbol = "circle"))
fig_4 <- plot_ly(mtcars, type = "scatter3d", x = ~mpg, y = ~cyl, z = ~ wt, color = ~as.factor(carb),
colors = c("green", "pink", "cyan", "purple"), scene = "scene4",
mode = "markers", marker = list(size = 5, symbol = "circle"))
#Can be combined as subplots:
main_plot <- subplot(fig_1, fig_2, fig_3, fig_4, nrows = 2, margin = 0.06) %>%
layout(title = "Main Plot",
scene= list(domain = list(x=c(0,0.5), y=c(0.5,1)), aspectmode="cube"),
scene2 = list(domain = list(x=c(0.5,1), y=c(0.5,1)), aspectmode="cube"),
scene3 = list(domain = list(x=c(0,0.5), y=c(0,0.5)), aspectmode="cube"),
scene4 = list(domain = list(x=c(0.5,1), y=c(0,0.5)), aspectmode="cube")
)
main_plot
#OR alternatively they can be combined as widgets:
combineWidgets(fig_1, fig_2, fig_3, fig_4)
到目前为止还不错,但我曾希望合并后的3D绘图能以某种方式同步,这样当我拖动/zoom /旋转一个绘图时,其他3个绘图也会效仿并适应新的"视图".有没有人知道在R中是否有可能将组合的3D图形作为子图形或组合的窗口小部件来实现?
类似的问题也被问到了与通过Python(https://community.plotly.com/t/synchronize-camera-across-3d-subplots/22236)密谋的有关,尽管我还不能发现在R中是否已经或可以做一些类似的事情.
如果能得到任何帮助或建议,我将不胜感激.提前谢谢!
- 赞恩