当前位置:   article > 正文

R语言散点图、坐标轴、图例设置,plot/points/axis/legend_r如何给散点图添加坐标轴标签

r如何给散点图添加坐标轴标签

通过画下方这张图,了解到plot/points/axis/legend的用法。

转载请注明出处~
在这里插入图片描述

代码
直接复制粘贴到R软件或者RStudio中,就可以把图画出来了,大多出代码有相应的解释~

rm(list=ls()) #清除环境

#导入数据
Sample1 <- c(0:97) #对应非肿瘤组织的98个样本
Sample2 <- c(98:198) #对应肿瘤组织的101个样本
Non <- c(5789,6457,6922,7186,7370,7461,7552,7705,7760,7857,7901,7959,8011,8051,8092,
         8115,8148,8198,8228,8258,8277,8308,8333,8383,8399,8441,8459,8465,8490,8499,
         8507,8523,8536,8550,8556,8570,8578,8588,8594,8600,8607,8624,8634,8639,8650,
         8659,8668,8673,8677,8687,8692,8697,8707,8715,8721,8726,8738,8745,8753,8761,
         8764,8773,8779,8783,8786,8795,8798,8809,8811,8819,8821,8824,8826,8831,8833,
         8836,8837,8839,8841,8844,8852,8854,8856,8861,8863,8867,8870,8875,8877,8878,
         8881,8884,8888,8890,8894,8895,8898,8903)
Tumour <- c(8941,9009,9037,9045,9086,9137,9143,9147,9153,9159,9160,9168,9171,9181,
            9184,9191,9196,9198,9200,9204,9208,9214,9214,9216,9216,9218,9218,9222,
            9224,9224,9226,9228,9228,9229,9229,9229,9230,9232,9232,9235,9237,9237,
            9237,9238,9241,9245,9245,9245,9245,9245,9245,9246,9246,9247,9247,9248,
            9248,9248,9248,9248,9248,9248,9248,9248,9248,9248,9248,9248,9248,9248,
            9248,9248,9248,9248,9248,9248,9248,9249,9249,9249,9249,9250,9251,9251,
            9251,9252,9252,9252,9252,9252,9252,9252,9252,9252,9252,9252,9252,9252,
            9252,9252,9252)
all <- c(5789,6457,6922,7186,7370,7461,7552,7705,7760,7857,7901,7959,8011,8051,8092,
         8115,8148,8198,8228,8258,8277,8308,8333,8383,8399,8441,8459,8465,8490,8499,
         8507,8523,8536,8550,8556,8570,8578,8588,8594,8600,8607,8624,8634,8639,8650,
         8659,8668,8673,8677,8687,8692,8697,8707,8715,8721,8726,8738,8745,8753,8761,
         8764,8773,8779,8783,8786,8795,8798,8809,8811,8819,8821,8824,8826,8831,8833,
         8836,8837,8839,8841,8844,8852,8854,8856,8861,8863,8867,8870,8875,8877,8878,
         8881,8884,8888,8890,8894,8895,8898,8903,8941,9009,9037,9045,9086,9137,9143,
         9147,9153,9159,9160,9168,9171,9181,
            9184,9191,9196,9198,9200,9204,9208,9214,9214,9216,9216,9218,9218,9222,
            9224,9224,9226,9228,9228,9229,9229,9229,9230,9232,9232,9235,9237,9237,
            9237,9238,9241,9245,9245,9245,9245,9245,9245,9246,9246,9247,9247,9248,
            9248,9248,9248,9248,9248,9248,9248,9248,9248,9248,9248,9248,9248,9248,
            9248,9248,9248,9248,9248,9248,9248,9249,9249,9249,9249,9250,9251,9251,
            9251,9252,9252,9252,9252,9252,9252,9252,9252,9252,9252,9252,9252,9252,
            9252,9252,9252)

s <- (0:198) #对应总的199个样本
plot(s,all,type = "l", #type选l,只画线条不画散点
     xlab = "Sample number",ylab = "Number of protein identifications",
     col="#eec693",lwd=4, #lwd线条宽度
     axes=F, #取消全部坐标轴及坐标框
     ylim=c(5000,10000), #设置y轴显示范围,不然默认不显示500010000,因为数据少
     cex.lab=1.3) #坐标轴标题的大小
points(Sample1,Non,col="#4d8ac9",pch=17) #画非肿瘤组织样本的散点
points(Sample2,Tumour,col="#f06a6b",pch=17) #画肿瘤组织样本的散点
legend(list(x=20,y=6100), #设置legend显示的位置
       bty="n", #不显示legend框
       title = NA, #没有标题
       c("Non-tumour","Tumour"),pch=c(17,17),col=c("#4d8ac9","#f06a6b"),
       horiz = T, #两个分组并排展示
       pt.cex = 2, #points的大小 
       cex = 1, #文字的大小
       text.font=2, #坐标标签“1”为正常,“2”为加粗,“3”为斜体
       text.col = "black", #文字的颜色
       text.width = strwidth("100000000000000")) #两个分组之间的间距,“0”越多间隔越大
axis(2,at=c(5000,6000,7000,8000,9000,10000), #2表示设置左坐标轴(y轴)
     label=c("5,000","6,000","7,000","8,000","9,000","10,000"),lwd=3,
     lwd.ticks = 3,
     font.axis=2, #坐标标签“1”为正常,“2”为加粗,“3”为斜体
     cex.axis=1) #坐标标签大小,默认为1
axis(1,seq(0,200,50),seq(0,200,50),lwd = 3,lwd.ticks = 3, #1表示设置下方坐标轴(x轴)
     font.axis=2) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/270644
推荐阅读
相关标签
  

闽ICP备14008679号