将pch数据点符号插入R中的轴标签

时间:2013-06-11 11:23:32

标签: r text plot axis-labels pch

我已将两个数据集合并到一个图表中,我想将相应的pch符号添加到轴标签中。 现在,我知道使用text()代替xlabylab以及Hershey矢量字体(而不是引用pch=16等)的解决方案herehere但符号看起来有点不稳定。有没有人有更“全面”的解决方案?

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)

2 个答案:

答案 0 :(得分:3)

如果你坚持这样做:

par(mar=c(5,5,2,5), xpd=TRUE)

x <- seq(0,5,0.5)
y <- seq(0,5,0.5)
plot(x,y, xlab="", ylab="")


text(-1,2.5,"y axis text", cex=1.25, adj=0, srt=90)
points(-1,2.4)

答案 1 :(得分:0)

这应该有效:

mtext(paste0("your label text", " (",  intToUtf8(9679), ")"), side = 2, line=2.5)