[R] Mixing plotting symbols with text

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Wed Jun 8 00:41:23 CEST 2022


Hi Erin,
Here's a kinda clunky way to get your plot title. It can be modified
to do fancier things like intersperse symbols with letters but you may
need no more than this. Have fun.

par(mar=c(5,4,5,2))
plot(0,xlim=c(-1,1),ylim=c(-1,1),type="n",xlab="Nonsense",ylab="Intensity")
points(runif(4,-1,1),runif(4,-1,1),pch=3)
points(runif(4,-1,1),runif(4,-1,1),pch=4)
symbol_n_text<-function(x,y,pch,txt,adj=0,cex=1) {
 oldcex<-par(cex=cex)
 x<-x-(strwidth("M ")+strwidth(txt))/2
 points(x,y,pch=pch)
 x<-x+strwidth("M ")
 text(x,y,txt,adj=adj)
 par(oldcex)
}
par(xpd=TRUE)
symbol_n_text(0,1.35,3,"your stuff",cex=1.5)
symbol_n_text(0,1.2,4,"my stuff",cex=1.5)

Thanks for the nod, Bert.

Jim

On Wed, Jun 8, 2022 at 5:39 AM Erin Hodgess <erinm.hodgess using gmail.com> wrote:
>
> Hello!
>
> Hope you’re having a great day!
>
> I would like to combine plotting symbols with text.
>
> I have tried
> xp2a <- expression(paste(pch =3, “my stuff”))
> But when I use that as a plot title, it just shows as “3 my stuff”.
>
> I have a feeling that it’s going to be something very straightforward that
> I am missing.
>
> Thanks for your help,
> Sincerely,
> Erin
> --
> Erin Hodgess, PhD
> mailto: erinm.hodgess using gmail.com
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



More information about the R-help mailing list