R语言|绘制三维图

R语言绘制三维图△▲

大部分情况下,我们使用二维的图像就足以展示我们的数据,但是也无法排出在一些特定的情况下,需要将数据在三维空间进行展示,所以今天小编就给大家分享三维图的画法吧~

NO.01:三维点图

1.下载plot3D包并调用

BiocManager::install("plot3D")
library(plot3D)

2.绘制3D图的坐标向量

z <- seq(0, 20, 0.1)
x <- cos(z)
y <- sin(z)

3.绘制三维点图并美化
参数:phi:控制三维图的上下方向,col:点的颜色,pch:点的形状,cex:点放大多少倍,ticktype:坐标轴的刻度,bty:表示边框类型

scatter3D(x, y, z, 
          phi = 1, 
          col = ramp.col(col = c("cyan", "blue"),
          n = length(z)),pch =18, 
          cex = 1,  
          ticktype = "detailed",bty = "b2")

在这里插入图片描述

NO.02:三维线图
1.下载plot3D包并调用

BiocManager::install("plot3D")
library(plot3D)

2.绘制3D图的坐标向量

z <- seq(0, 20, 0.1)
x <- cos(z)
y <- sin(z)

3.绘制三维线图并美化

scatter3D(x, y, z,
          phi = 2, type = "l",
          col = ramp.col(col=c("cyan","red"),
          n=length(z)),ticktype = "detailed", 
          lwd = 2, bty = "g")

NO.03:三维点线图
1.下载plot3D包并调用

BiocManager::install("plot3D")
library(plot3D)

2.绘制3D图的坐标向量

z <- seq(0, 20, 0.1)
x <- cos(z)
y <- sin(z)

3.绘制三维点线图,type = "b"表示both,即点连线,bty指定边框类型

scatter3D(x, y, z, 
          phi = 2, type = "b",
          col = ramp.col(col=c("cyan","magenta"),
          n=length(z)),bty = "f",
          ticktype = "detailed", 
          pch = 15, 
          cex = c(0.5, 1, 1.5))

以上就是关于一些三维图画法的分享啦! 如果对生信绘图感兴趣的小伙伴,可以添加“小图”的微信或者搜索微信公众号“作图帮”,图图期待你们的加入!

猜你喜欢

转载自blog.csdn.net/weifanbio/article/details/120521866