一篇就够了!scatterplot3D包终极指南,让你的二维数据‘立’起来
公众号后台回复“111”领取本篇代码、基因集或示例数据等文件;
文件编号:240115
果粉福利:生信人必备神器——服务器
平时生信分析学习中有要的小伙伴可以联系小果租赁,粉丝福利都是市场超低价格,赶快找小果领取免费的试用账号吧!
#安装R包及调用
install.packages('scatterplot3d')
library(scatterplot3d)
library(RColorBrewer)
#读入数据
data <- read.table('输入数据.txt',sep = 't',row.names = 1,header = T)
data
#设置颜色,因为每个基因设置了10个数据,因此选取两个色系
Set1 <- brewer.pal(n=6,name = 'Set1')
Set2 <- brewer.pal(n=6,name = 'Set2')
Set <- unique(c(Set2,Set1))
#简单出图
P1 <- scatterplot3d(x = data$Gene1,y = data$Gene2,z = data$Gene3)
#对轴标题的调节
P2 <- scatterplot3d(x = data$Gene1,y = data$Gene2,z = data$Gene3,
xlab = 'Gene1',ylab = 'Gene2',zlab = 'Gene3',
main = 'scatterplot3d',sub = 'test')
#对字体大小进行调节
P3 <- scatterplot3d(x = data$Gene1,y = data$Gene2,z = data$Gene3,
xlab = 'Gene1',ylab = 'Gene2',zlab = 'Gene3',
main = 'scatterplot3d',sub = 'test',
cex.lab = 2,cex.axis = 1,cex.symbols = 4, #分别是轴标题,轴标签及点的大小
font.lab = 45)
#对线进行调节
P4 <- scatterplot3d(x = data$Gene1,y = data$Gene2,z = data$Gene3,
xlab = 'Gene1',ylab = 'Gene2',zlab = 'Gene3',main = 'scatterplot3d',sub = 'test',
grid = T, #底面是否有横线
box = F, #是否添加其余边
#x.ticklabs = colnames(data), #用于指定刻度
lty.grid = 3, #底面线的类型
lty.axis = 2, #坐标轴线的类型
ylim = c(-2,2),xlim = c(-2,2),zlim = c(-2,2), #各坐标轴的长度
col.grid = 'grey',col.axis = 'grey' #分别对底线/坐标轴的颜色进行改变
)
#给定形状参数
shape <- c(16,17)
#其余小函数
P5 <- scatterplot3d(x = data$Gene1,y = data$Gene2,z = data$Gene3,
xlab = 'Gene1',ylab = 'Gene2',zlab = 'Gene3',main = 'scatterplot3d',sub = 'test',
pch = shape[factor(data$group)],color = Set[factor(data$group)], #点的形状及颜色
cex.lab = 2,cex.axis = 1,cex.symbols = 2, #分别是轴标题,轴标签及点的大小
ylim = c(-2,2.5),xlim = c(-2,2),zlim = c(-2,2), #各坐标轴的长度
scale.y = 2, #y轴单个方框的宽度
angle = 25, #长方体整体角度
lab.z = c(3,5),grid = T, #底面是否有横线
box = F, #是否添加其余边框
#表示点的状态,‘p’是只有点,‘l’是只有线,‘h’是既有点到底面的垂线,‘b’是点与线互相连接
type = 'h',
#x.ticklabs = colnames(data), #用于指定刻度
lty.grid = 3, #底面线的类型
lty.axis = 2, #坐标轴线的类型
col.grid = 'grey',col.axis = 'grey',col.lab = 'black' #分别对底线/坐标轴的颜色进行改变
)
#添加图例和文本信息:
legend("topright", legend = c("A", "B"),
col = Set, pch = c(16, 17))
#前面的数字是根据底线的条数来决定的哦,但是中间的数的确是根据z轴坐标而定
text(1.1,-0.2,1,labels = 'sample00') #当然是可以改变颜色和大小的啊
text(1,0.5,-0.3,labels = 'samplexx',col = 'red4',cex = 1.5)
往期推荐