[R] plus/minus +/- in factor; not plotmath not expression
Duncan Murdoch
murdoch.duncan at gmail.com
Mon Dec 2 22:01:42 CET 2013
On 02/12/2013 2:22 PM, Jacob Wegelin wrote:
> I want to put the "plus or minus" symbol into a character variable, so that this can be turned into a factor and be displayed in the "strip" of a faceted ggplot2 plot.
>
> A very nice solution, thanks to Professor Ripley's post of Nov 16, 2008; 3:13pm, visible at http://r.789695.n4.nabble.com/Symbols-to-use-in-text-td874239.html and subsequently http://www.fileformat.info/info/unicode/char/00b1/index.htm, is:
>
> junk<- "\u00B1"
> print(junk)
>
> # This works very nicely. For instance:
>
> junk<-data.frame(gug=c(
> rep( "\u00B1 1.2", 10)
> ,
> rep( "\u00B1 2.3", 10)
> )
> )
> junk$eks<-1:nrow(junk)
> junk$why<-with(junk, as.numeric(gug) + eks)
> print(summary(junk))
> library(ggplot2)
> print(
> ggplot(data=junk, mapping=aes(x=eks, y=why))
> + geom_point()
> + facet_grid(. ~ gug)
> )
>
> This works very nicely on my system, but I just wanted to enquire:
>
> Is this machine-independent and stable?
It is machine-independent and stable because \u00B1 means "Unicode
PLUS-MINUS SIGN", but it is not device-independent. There may be a
graphics device that does not support all Unicode characters. I'd
guess it is pretty widely available though.
>
> Is there a "native R" way to do this?
That is native R.
Duncan Murdoch
>
> I did this in:
>
> > sessionInfo()
> R version 2.15.3 (2013-03-01)
> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
> other attached packages:
> [1] ggplot2_0.9.3.1
>
> loaded via a namespace (and not attached):
> [1] colorspace_1.2-0 dichromat_1.2-4 digest_0.6.0 grid_2.15.3 gtable_0.1.2 labeling_0.1
> [7] MASS_7.3-23 munsell_0.4 plyr_1.8 proto_0.3-10 psych_1.2.8 RColorBrewer_1.0-5
> [13] reshape2_1.2.2 scales_0.2.3 stringr_0.6.2
> >
>
> Incidentally (and for the sake of keyword searches): Although a google search initially led me to posts about expression() and plotmath, those eventually had nothing to do with the solution.
>
> Jacob A. Wegelin
> Assistant Professor
> Department of Biostatistics
> Virginia Commonwealth University
> 830 E. Main St., Seventh Floor
> P. O. Box 980032
> Richmond VA 23298-0032
> U.S.A.
> CTSA grant: UL1TR000058
> URL: http://www.people.vcu.edu/~jwegelin
>
> ______________________________________________
> 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.
More information about the R-help
mailing list