你可以使用plot3Drgl图书馆。例如
library("plot3Drgl")
x <- c(1,2,3,4,5)
y <- c(6,7,8,9,10)
z <- c(11,12,13,14,15)
colors <- c(rep("red",3), rep("blue",2))
plot3d(x=x,y=y,z=z,col=colors)
或者您可以使用plotly:
library("plotly")
x <- c(1,2,3,4,5)
y <- c(6,7,8,9,10)
z <- c(11,12,13,14,15)
colors <- c(rep("red",3), rep("blue",2))
df<-as.data.frame(cbind(x,y,z,colors))
colnames(df)<-c("eat", "pork", "chops", "colors")
p <- plot_ly(data=df, x=~eat, y=~pork, z=~chops, color =~colors, colors=c('#BF382A', '#0C4B8E')) %>% ## Like a pipe?
add_markers() %>%
layout(scene = list(xaxis = list(title = 'eat'),
yaxis = list(title = 'pork'),
zaxis = list(title = 'chops')))
htmlwidgets::saveWidget(as_widget(p), "index.html")
这会将输出保存为 html 文件。为了让它工作,你还需要安装 pandoc。在 CentOS/RedHat 上做yum install pandoc pandoc-citeproc. 在 Mac OSX 上,使用homebrew,执行brew install pandoc.