微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

R:3D 散点图未显示在 Web 浏览器中

如何解决R:3D 散点图未显示在 Web 浏览器中

在创建自己的一些 3D 散点图之前,我正在尝试遵循教程 here

# library
library(rgl)
options(rgl.printRglwidget = TRUE)

# This is to output a rgl plot in a rmarkdown document. Note that you must add webgl=TRUE,results='hide' in the chunck header
library(knitr)
knit_hooks$set(webgl = hook_webgl)

# Data: the iris data is provided by R
data <- iris

# Add a new column with color
mycolors <- c('royalblue1','darkcyan','oldlace')
data$color <- mycolors[ as.numeric(data$Species) ]

# Plot
par(mar=c(0,0))
plot3d( 
  x=data$`Sepal.Length`,y=data$`Sepal.Width`,z=data$`Petal.Length`,col = data$color,type = 's',radius = .1,xlab="Sepal Length",ylab="Sepal Width",zlab="Petal Length")


writeWebGL( filename="3dscatter.html",width=600,height=600)

然而,在这样做之后,似乎发生了两件事。首先,我收到以下警告:

Warning messages:
1: In snapshot3d(scene = x,width = width,height = height) :
  webshot = TRUE requires the webshot2 package; using rgl.snapshot() instead
2: In rgl.snapshot(filename,fmt,top) :
  this build of rgl does not support snapshots

我不知道 snapshot 是什么意思,因为它不在我的代码中。第二件事是我运行后,一个名为 3dscatter.html文件出现在我的工作目录中,但我转到浏览器,我没有看到我的情节。 Javascript 已启用。有人可以帮我弄清楚我在这里缺少什么吗?

enter image description here

解决方法

@IRTFM 的建议奏效了。我替换了该行:

writeWebGL( filename="3dscatter.html",width=600,height=600)

htmlwidgets::saveWidget(rglwidget(),filename)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。