• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

R语言 三维画图

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

#三维绘图

install.packages("scatterplot3d")  #安装包

library(scatterplot3d)

#散点图是描述二元变量关系的图,如果需要一次性对三个变量交互关系进行可视化,可使用三维图

#scatterplot3d(x,y,z),x绘制在横轴上,y绘制在竖轴上,z绘制在透视轴上

z=seq(-10,10,0.01)

x=cos(z)

y=sin(z)

scatterplot3d(x,y,z,highlight.3d = TRUE)

#scatterplot3d只能画静态三维图,如果需要交互旋转对三维图,可采用rgl

install.packages("rgl") #安装包

library(rgl)   #加载包

attach(iris)   #**iris数据集,使之成为当前数据集

head(iris)   #数据前六行

library(rgl)

a=Species

levels(a)=c("Green","Red","Blue")  #为不同种类对花画不同颜色

plot3d(Sepal.Length,Sepal.Width,Petal.Length,col=a,size=10)#可以拖动旋转对图

 

 

 

#软件操作结果

> #三维绘图

> install.packages("scatterplot3d")

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/scatterplot3d_0.3-41.zip'

Content type 'application/zip' length 338005 bytes (330 KB)

downloaded 330 KB

 

package ‘scatterplot3d’ successfully unpacked and MD5 sums checked

 

The downloaded binary packages are in

      C:\Users\L3M307NJSJ\AppData\Local\Temp\Rtmpg9VZkz\downloaded_packages

> library(scatterplot3d)

> #散点图是描述二元变量关系的图,如果需要一次性对三个变量交互关系进行可视化,可使用三维图

> #scatterplot3d(x,y,z),x绘制在横轴上,y绘制在竖轴上,z绘制在透视轴上

> z=seq(-10,10,0.01)

> x=cos(z)

> y=sin(z)

> scatterplot3d(x,y,z,highlight.3d = TRUE)

 

> #scatterplot3d只能画静态三维图,如果需要交互旋转对三维图,可采用rgl

> #scatterplot3d只能画静态三维图,如果需要交互旋转对三维图,可采用rgl
> install.packages("rgl")
also installing the dependencies ‘colorspace’, ‘assertthat’, ‘utf8’, ‘ps’, ‘labeling’, ‘munsell’, ‘RColorBrewer’, ‘cli’, ‘fansi’, ‘pillar’, ‘pkgconfig’, ‘processx’, ‘glue’, ‘stringi’, ‘BH’, ‘gtable’, ‘plyr’, ‘reshape2’, ‘scales’, ‘tibble’, ‘viridisLite’, ‘withr’, ‘callr’, ‘yaml’, ‘digest’, ‘Rcpp’, ‘evaluate’, ‘highr’, ‘markdown’, ‘stringr’, ‘xfun’, ‘httpuv’, ‘mime’, ‘xtable’, ‘R6’, ‘sourcetools’, ‘later’, ‘promises’, ‘crayon’, ‘rlang’, ‘lazyeval’, ‘ggplot2’, ‘miniUI’, ‘base64enc’, ‘webshot’, ‘htmlwidgets’, ‘htmltools’, ‘knitr’, ‘jsonlite’, ‘shiny’, ‘magrittr’, ‘crosstalk’, ‘manipulateWidget’
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/colorspace_1.4-1.zip'
Content type 'application/zip' length 2548685 bytes (2.4 MB)
downloaded 2.4 MB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/assertthat_0.2.1.zip'
Content type 'application/zip' length 53947 bytes (52 KB)
downloaded 52 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/utf8_1.1.4.zip'
Content type 'application/zip' length 214672 bytes (209 KB)
downloaded 209 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/ps_1.3.0.zip'
Content type 'application/zip' length 306802 bytes (299 KB)
downloaded 299 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/labeling_0.3.zip'
Content type 'application/zip' length 61756 bytes (60 KB)
downloaded 60 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/munsell_0.5.0.zip'
Content type 'application/zip' length 243643 bytes (237 KB)
downloaded 237 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/RColorBrewer_1.1-2.zip'
Content type 'application/zip' length 55498 bytes (54 KB)
downloaded 54 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/cli_1.1.0.zip'
Content type 'application/zip' length 172817 bytes (168 KB)
downloaded 168 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/fansi_0.4.0.zip'
Content type 'application/zip' length 220260 bytes (215 KB)
downloaded 215 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/pillar_1.3.1.zip'
Content type 'application/zip' length 155023 bytes (151 KB)
downloaded 151 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/pkgconfig_2.0.2.zip'
Content type 'application/zip' length 22071 bytes (21 KB)
downloaded 21 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/processx_3.3.0.zip'
Content type 'application/zip' length 310218 bytes (302 KB)
downloaded 302 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/glue_1.3.1.zip'
Content type 'application/zip' length 172085 bytes (168 KB)
downloaded 168 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/stringi_1.4.3.zip'
Content type 'application/zip' length 15289558 bytes (14.6 MB)
downloaded 14.6 MB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/BH_1.69.0-1.zip'
Content type 'application/zip' length 19008161 bytes (18.1 MB)
downloaded 18.1 MB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/gtable_0.3.0.zip'
Content type 'application/zip' length 432854 bytes (422 KB)
downloaded 422 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/plyr_1.8.4.zip'
Content type 'application/zip' length 1297960 bytes (1.2 MB)
downloaded 1.2 MB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/reshape2_1.4.3.zip'
Content type 'application/zip' length 626806 bytes (612 KB)
downloaded 612 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/scales_1.0.0.zip'
Content type 'application/zip' length 1065280 bytes (1.0 MB)
downloaded 1.0 MB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/tibble_2.1.1.zip'
Content type 'application/zip' length 334718 bytes (326 KB)
downloaded 326 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/viridisLite_0.3.0.zip'
Content type 'application/zip' length 60487 bytes (59 KB)
downloaded 59 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/withr_2.1.2.zip'
Content type 'application/zip' length 151095 bytes (147 KB)
downloaded 147 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/callr_3.2.0.zip'
Content type 'application/zip' length 253284 bytes (247 KB)
downloaded 247 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/yaml_2.2.0.zip'
Content type 'application/zip' length 203556 bytes (198 KB)
downloaded 198 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/digest_0.6.18.zip'
Content type 'application/zip' length 194633 bytes (190 KB)
downloaded 190 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/Rcpp_1.0.1.zip'
Content type 'application/zip' length 4509418 bytes (4.3 MB)
downloaded 4.3 MB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/evaluate_0.13.zip'
Content type 'application/zip' length 74020 bytes (72 KB)
downloaded 72 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/highr_0.8.zip'
Content type 'application/zip' length 48182 bytes (47 KB)
downloaded 47 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/markdown_0.9.zip'
Content type 'application/zip' length 189669 bytes (185 KB)
downloaded 185 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/stringr_1.4.0.zip'
Content type 'application/zip' length 215326 bytes (210 KB)
downloaded 210 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/xfun_0.6.zip'
Content type 'application/zip' length 166108 bytes (162 KB)
downloaded 162 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/httpuv_1.5.1.zip'
Content type 'application/zip' length 1492098 bytes (1.4 MB)
downloaded 1.4 MB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/mime_0.6.zip'
Content type 'application/zip' length 47809 bytes (46 KB)
downloaded 46 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/xtable_1.8-4.zip'
Content type 'application/zip' length 704814 bytes (688 KB)
downloaded 688 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/R6_2.4.0.zip'
Content type 'application/zip' length 58280 bytes (56 KB)
downloaded 56 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/sourcetools_0.1.7.zip'
Content type 'application/zip' length 530467 bytes (518 KB)
downloaded 518 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/later_0.8.0.zip'
Content type 'application/zip' length 610999 bytes (596 KB)
downloaded 596 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/promises_1.0.1.zip'
Content type 'application/zip' length 694951 bytes (678 KB)
downloaded 678 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/crayon_1.3.4.zip'
Content type 'application/zip' length 749454 bytes (731 KB)
downloaded 731 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/rlang_0.3.4.zip'
Content type 'application/zip' length 1081276 bytes (1.0 MB)
downloaded 1.0 MB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/lazyeval_0.2.2.zip'
Content type 'application/zip' length 171061 bytes (167 KB)
downloaded 167 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/ggplot2_3.1.1.zip'
Content type 'application/zip' length 3621964 bytes (3.5 MB)
downloaded 3.5 MB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/miniUI_0.1.1.1.zip'
Content type 'application/zip' length 36181 bytes (35 KB)
downloaded 35 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/base64enc_0.1-3.zip'
Content type 'application/zip' length 43316 bytes (42 KB)
downloaded 42 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/webshot_0.5.1.zip'
Content type 'application/zip' length 140929 bytes (137 KB)
downloaded 137 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/htmlwidgets_1.3.zip'
Content type 'application/zip' length 805004 bytes (786 KB)
downloaded 786 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/htmltools_0.3.6.zip'
Content type 'application/zip' length 661205 bytes (645 KB)
downloaded 645 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/knitr_1.22.zip'
Content type 'application/zip' length 1470621 bytes (1.4 MB)
downloaded 1.4 MB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/jsonlite_1.6.zip'
Content type 'application/zip' length 1160804 bytes (1.1 MB)
downloaded 1.1 MB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/shiny_1.3.1.zip'
Content type 'application/zip' length 4662692 bytes (4.4 MB)
downloaded 4.4 MB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/magrittr_1.5.zip'
Content type 'application/zip' length 155847 bytes (152 KB)
downloaded 152 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/crosstalk_1.0.0.zip'
Content type 'application/zip' length 665491 bytes (649 KB)
downloaded 649 KB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/manipulateWidget_0.10.0.zip'
Content type 'application/zip' length 1858183 bytes (1.8 MB)
downloaded 1.8 MB
 
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/rgl_0.100.19.zip'
Content type 'application/zip' length 4182731 bytes (4.0 MB)
downloaded 4.0 MB
 
package ‘colorspace’ successfully unpacked and MD5 sums checked
package ‘assertthat’ successfully unpacked and MD5 sums checked
package ‘utf8’ successfully unpacked and MD5 sums checked
package ‘ps’ successfully unpacked and MD5 sums checked
package ‘labeling’ successfully unpacked and MD5 sums checked
package ‘munsell’ successfully unpacked and MD5 sums checked
package ‘RColorBrewer’ successfully unpacked and MD5 sums checked
package ‘cli’ successfully unpacked and MD5 sums checked
package ‘fansi’ successfully unpacked and MD5 sums checked
package ‘pillar’ successfully unpacked and MD5 sums checked
package ‘pkgconfig’ successfully unpacked and MD5 sums checked
package ‘processx’ successfully unpacked and MD5 sums checked
package ‘glue’ successfully unpacked and MD5 sums checked
package ‘stringi’ successfully unpacked and MD5 sums checked
package ‘BH’ successfully unpacked and MD5 sums checked
package ‘gtable’ successfully unpacked and MD5 sums checked
package ‘plyr’ successfully unpacked and MD5 sums checked
package ‘reshape2’ successfully unpacked and MD5 sums checked
package ‘scales’ successfully unpacked and MD5 sums checked
package ‘tibble’ successfully unpacked and MD5 sums checked
package ‘viridisLite’ successfully unpacked and MD5 sums checked
package ‘withr’ successfully unpacked and MD5 sums checked
package ‘callr’ successfully unpacked and MD5 sums checked
package ‘yaml’ successfully unpacked and MD5 sums checked
package ‘digest’ successfully unpacked and MD5 sums checked
package ‘Rcpp’ successfully unpacked and MD5 sums checked
package ‘evaluate’ successfully unpacked and MD5 sums checked
package ‘highr’ successfully unpacked and MD5 sums checked
package ‘markdown’ successfully unpacked and MD5 sums checked
package ‘stringr’ successfully unpacked and MD5 sums checked
package ‘xfun’ successfully unpacked and MD5 sums checked
package ‘httpuv’ successfully unpacked and MD5 sums checked
package ‘mime’ successfully unpacked and MD5 sums checked
package ‘xtable’ successfully unpacked and MD5 sums checked
package ‘R6’ successfully unpacked and MD5 sums checked
package ‘sourcetools’ successfully unpacked and MD5 sums checked
package ‘later’ successfully unpacked and MD5 sums checked
package ‘promises’ successfully unpacked and MD5 sums checked
package ‘crayon’ successfully unpacked and MD5 sums checked
package ‘rlang’ successfully unpacked and MD5 sums checked
package ‘lazyeval’ successfully unpacked and MD5 sums checked
package ‘ggplot2’ successfully unpacked and MD5 sums checked
package ‘miniUI’ successfully unpacked and MD5 sums checked
package ‘base64enc’ successfully unpacked and MD5 sums checked
package ‘webshot’ successfully unpacked and MD5 sums checked
package ‘htmlwidgets’ successfully unpacked and MD5 sums checked
package ‘htmltools’ successfully unpacked and MD5 sums checked
package ‘knitr’ successfully unpacked and MD5 sums checked
package ‘jsonlite’ successfully unpacked and MD5 sums checked
package ‘shiny’ successfully unpacked and MD5 sums checked
package ‘magrittr’ successfully unpacked and MD5 sums checked
package ‘crosstalk’ successfully unpacked and MD5 sums checked
package ‘manipulateWidget’ successfully unpacked and MD5 sums checked
package ‘rgl’ successfully unpacked and MD5 sums checked
 
The downloaded binary packages are in
      C:\Users\L3M307NJSJ\AppData\Local\Temp\Rtmpg9VZkz\downloaded_packages
> attach(iris)
> head(iris)
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa
6          5.4         3.9          1.7         0.4  setosa
> library(rgl)
> a=Species
> levels(a)=c("Green","Red","Blue")  #为不同种类对花画不同颜色
> plot3d(Sepal.Length,Sepal.Width,Petal.Length,col=a,size=10)   #可以拖动旋转的图


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap