【发布时间】:2013-06-11 11:23:32
【问题描述】:
我已将两个数据集合并为一个图表,我想将相应的 pch 符号添加到轴标签中。
现在,我知道使用text() 而不是xlab 和ylab 和Hershey 矢量字体(而不是引用pch=16 等)的解决方案给出了here 和here 但这些符号看起来有点不靠谱-成形。有没有人有更“全面”的解决方案?
thinkoholic.com 的可重现示例,
par(mar=c(5,5,2,5))
# create data and plot circles
x <- seq(0,5,0.5)
y <- seq(0,5,0.5)
plot(x,y, xlab="", ylab="")
#create random data and add bullets (pch=19)
x <- rnorm(20,2.5)
y <- rnorm(20,2.5)
points(x,y, pch=19)
#add y axis on right side
axis (side = 4)
#create text with symbols
text(-1,2.5,"\\#H0850 y1 axis text", vfont=c("sans serif","plain"), cex=1.25, adj=0.5, srt=90, xpd=TRUE)
text(6,2.5,"\\#H0902 y2 axis text", vfont=c("sans serif","plain"), cex=1.25, adj=0.5, srt=90, xpd=TRUE)
text(2.5,-1,"x axis text", vfont=c("sans serif","plain"), cex=1.25, adj=0.5, srt=0, xpd=TRUE)
【问题讨论】:
-
如果失真无法解决,一个选项是不在原始图上绘制轴,而是在
xlim和ylim上绘制大于所需大小的图。然后返回并使用text在展开的绘图区域内而不是在边距中绘制轴,您的points将在绘图空间而不是边距中,并且不应扭曲。不过,这有点像 hack,我敢肯定有人有更好的主意。 -
请给出一个可重现的例子。另外,我建议不要这样做。虽然我不完全同意永远不应该使用辅助轴的观点,但我坚信除了数据点之外的符号应该只出现在图例中。
标签: r text plot axis-labels pch