【问题标题】:Inserting pch data point symbols into axis labels in R将pch数据点符号插入R中的轴标签
【发布时间】:2013-06-11 11:23:32
【问题描述】:

我已将两个数据集合并为一个图表,我想将相应的 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)

【问题讨论】:

  • 如果失真无法解决,一个选项是不在原始图上绘制轴,而是在xlimylim 上绘制大于所需大小的图。然后返回并使用text 在展开的绘图区域内而不是在边距中绘制轴,您的points 将在绘图空间而不是边距中,并且不应扭曲。不过,这有点像 hack,我敢肯定有人有更好的主意。
  • 请给出一个可重现的例子。另外,我建议不要这样做。虽然我不完全同意永远不应该使用辅助轴的观点,但我坚信除了数据点之外的符号应该只出现在图例中。

标签: r text plot axis-labels pch


【解决方案1】:

如果你坚持这样做:

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)

【讨论】:

    【解决方案2】:

    这应该可行:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-14
      • 1970-01-01
      • 2023-01-09
      • 1970-01-01
      • 2020-08-19
      • 2016-01-22
      • 1970-01-01
      相关资源
      最近更新 更多