R:带有注释的多个x轴 [英] R: multiple x axis with annotations

查看:159
本文介绍了R:带有注释的多个x轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在R中的一个图上添加多个x轴?并在每个比例尺旁边添加注释?

Is it possible to add more than one x-axis to a plot in R? And to put an annotation next to each scale?

编辑>这是Nick Sabbe想法的结果.对于注释(每个轴的左侧都有一些文字),可以吗?

Edit > here's the result of Nick Sabbe idea. For the annotation (a little text at the left of each axis), is it possible ?

推荐答案

您可以使用axis()line参数将一个轴放置在更高或更低的位置,这样您就可以制造多个轴.然后,使用mtext()可以在侧面添加标签.请注意,绘图本身仅在一个比例尺上,因此您需要相应地重新缩放另一比例尺的点和标签:

You can use the line argument of axis() to place an axis higher or lower, this way you can make multiple axes. With mtext() you can then add a label to the side. Do note that the plot itself is only on one scale so you need to rescale the points and labels of the other scale accordingly:

# Plot and first axis:
plot(1:10,1:10,bty="n",col="red",pch=16,axes=FALSE,xlab="",ylab="")
axis(2,0:11,las=1)
axis(1,0:11,line=1,col="red",col.ticks="red",col.axis="red")
mtext("Label 1",1,line=1,at=0.2,col="red")

# Secondary points and axis:
points(rnorm(10,50,20)/10, rnorm(10,5,2),pch=16, col="blue" )
axis(1,0:11,labels=0:11*10,line=3,col="blue",col.ticks="blue",col.axis="blue")
mtext("Label 2",1,line=3,at=0.2,col="blue")

这篇关于R:带有注释的多个x轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆