R语言 画半透明散点图

时间:2024-05-23 08:28:33

# 读取文件

redfile <-read.table('D:\\task\\F\\example.out') 

par(mar=c(5, 5, 5, 5)) # 调整图像大小
# 第一张图,设置xlim,ylim,把纵坐标轴设为False
plot(redfile$V3, redfile$V4, pch=16, xlim=c(40, 52), ylim=c(62, 94), cex=1.5, yaxt="n", ann=F, col=rgb(0, 0, 255, 40, maxColorValue=255))
# 设置左坐标轴的刻度、颜色。
axis(side=2, at=seq(length=17, from=62, to=94), col.axis="blue", col.ticks="blue")
par(new=T) # 保持当前图不动,添加新图
# 保证两张图的横坐标范围一样
plot(redfile$V3, redfile$V5, pch=16, xlim=c(40, 52), ylim=c(0, 2.4), cex=1.5, axes=F, ann=F, col=rgb(0, 255, 0, 40, maxColorValue=255))
# 设置右纵坐标刻度、颜色
axis(side=4, at=seq(length=13, from=0, to=2.4), col.axis="green", col.ticks="green")
# 标注
mtext("1223", side=1, line=3)

mtext("4556", side=2, line=3, col="blue")

mtext("7889", side=4, line=3, col="green")

title(main="123456")

输出结果如下:

R语言 画半透明散点图