[R] Include plotting symbals pch 16 and 17 into captions / text in pdf graph

David Winsemius dwinsemius at comcast.net
Mon Jul 21 22:37:26 CEST 2014


It's a hack but this works:

cairo_pdf("utftext.pdf", family="Calibri")
plot(0:1,0:1, type="n")
points(0.2, 1, pch=16)
mtext(
       text = "pch=16 (\U25CF)",
       side = 3,
       at   = 0.2,
       line = 1,
   )
points(0.8, 1, pch=17); points(0.85, 1.1, pch=17, xpd=TRUE)
# par(xpd=TRUE) lets plotting go outside the usual clipping box.

mtext(
       text = "pch=17 (  )",  # makes room for the triangle
       side = 3,
       at   = 0.8,
       line = 1
   )
dev.off()

-- 
David.

On Jul 21, 2014, at 5:10 AM, Rainer M Krug wrote:

> 
> Hi
> 
> I want to include the plotting symbols pch=16 and pch=17 in text in
> the graph used as labels.
> 
> This works:
> 
> --8<---------------cut here---------------start------------->8---
> plot(0:1,0:1, type="n")
> points(0.2, 1, pch=16)
> mtext(
>        text = "pch=16 (\U25CF)",
>        side = 3,
>        at   = 0.2,
>        line = 1,
>    )
> points(0.8, 1, pch=17)
> mtext(
>        text = "pch=17 (\U25B2)",
>        side = 3,
>        at   = 0.8,
>        line = 1
>    )
> --8<---------------cut here---------------end--------------->8---
> 
> But I would need this as a pdf and in Calibri font, which does not
> include the UTF symbol \U25B2 (the triangle). I got that far:
> 
> --8<---------------cut here---------------start------------->8---
> 
> cairo_pdf("utftext.pdf", family="Calibri")
> plot(0:1,0:1, type="n")
> points(0.2, 1, pch=16)
> mtext(
>        text = "pch=16 (\U25CF)",
>        side = 3,
>        at   = 0.2,
>        line = 1,
>    )
> points(0.8, 1, pch=17)
> mtext(
>        text = "pch=17 (\U25B2)",
>        side = 3,
>        at   = 0.8,
>        line = 1
>    )
> dev.off()
> --8<---------------cut here---------------end--------------->8---
> 
> which results in the attached pdf (hope it comes through). If not: the
> utf symbol for the upward error is displayed as an empty square with a
> question mark in it).
> 
> Is there a way that I can show the plotting symbol pch=17 in the caption
> when using this font?
> 
> Thanks,
> 
> Rainer
> 
> -- 
> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)
> 
> Centre of Excellence for Invasion Biology
> Stellenbosch University
> South Africa
> 
> Tel :       +33 - (0)9 53 10 27 44
> Cell:       +33 - (0)6 85 62 59 98
> Fax :       +33 - (0)9 58 10 27 44
> 
> Fax (D):    +49 - (0)3 21 21 25 22 44
> 
> email:      Rainer at krugs.de
> 
> Skype:      RMkrug
> 
> PGP: 0x0F52F982
> <utftext.pdf>______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list