1

I have combined two data sets into one graph and I would like to add the corresponding pch symbols right into the axis labels. Now, I know that solutions using text() instead of xlab and ylab and Hershey vector fonts (instead of citing a pch=16, etc.) are given here and here but the symbols appear kinda wonky-shaped. Does anyone have a more "well-rounded" solution?

thinkoholic.com's reproducible example,

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)
Brian
  • 349
  • 4
  • 16
  • One option, if the distortion is not solvable, is to not draw axes on your original plot(s) and to draw the plot larger than it needs to be on `xlim` and `ylim`. Then go back in and draw axes using `text` within the expanded plot area rather than in the margins and your `points` will be in the plotting space rather than margins and should not be distorted. That's sort of a hack, though, and I'm sure someone has a better idea. – Thomas Jun 11 '13 at 11:39
  • 1
    Please give a reproducible example. Also, I recommend not to do this. While I do not fully agree with the opinion that secondary axes should never be used, I strongly believe that symbols besides the data points should only appear in a legend. – Roland Jun 11 '13 at 11:40

2 Answers2

2

If you insist on doing this:

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)
Roland
  • 127,288
  • 10
  • 191
  • 288
0

This should work:

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