R如何绘制带箭头的坐标轴

作者: Stat_lysis | 来源:发表于2021-06-08 11:02 被阅读0次

    R绘制带箭头的坐标轴,两个参数需要提前设置

    第一,xpd=NA,否则绘制箭头只会显示一半

    xpd参数说明:A logical value or NA. If FALSE, all plotting is clipped to the plot region, if TRUE, all plotting is clipped to the figure region, and if NA, all plotting is clipped to the device region. 

    第二,横纵坐标由于默认是多增加4%的区间,因此要么设置xaxs=“i" 和 yaxs ="i",让坐标轴交于结束位置

    或者直接用par()['usr'][[1]] 找出绘制的起点和终点

    在R语言中,这两个参数的取值包括 5种,其中"r"是默认值,就是我们上边讲到的添加4%的一个距离,"i" 代表的行为是原始数据的最小值到最大值是多少,对应的坐标轴的起始和终止位置就是多少

    举例:par(xpd=NA)

    plot(c(1:10),c(1:10),type="l",bty="l",xlab="X",ylab="Y")

    ord<-par("usr")

    arrows(x0 = ord[1],y0=ord[3],x1=ord[2]*1.05,y1=ord[3])

    arrows(x0 = ord[1],y0=ord[3],x1=ord[1],y1=ord[4]*1.05)

    绘制

    相关文章

      网友评论

        本文标题:R如何绘制带箭头的坐标轴

        本文链接:https://www.haomeiwen.com/subject/sgesrltx.html