[R] Properly Parsing Pre-Superscripts & Displaying Them With grid.text
Bryan Hanson
hanson at depauw.edu
Fri Aug 1 23:23:51 CEST 2008
Hi all... I¹m making a chart dealing with frequencies of isotopes of various
elements. For instance, I'd like the following text to appear on a chart
with the "35" and "37" as superscripts:
Based upon:
35Cl: 75%
37Cl: 25%
I am having problems properly parsing the superscript that preceeds the
"Cl", since there is no character ahead of the superscript (I saw examples
in the archives where there was a preceeding character). Also, the
construction of the string seems to not be working as I expect either. So,
I think there are two problems here. Here is a sample of what doesn't quite
work:
Cl1 <- rbinom(1000, size = 1, prob = 0.25)
pCl1 <- histogram(Cl1, main = expression(Cl[1]), xlab = "", ylab = "",
scales = list(draw = FALSE), ylim = c(0:80))
plot(pCl1)
# This works fine but doesn't have everything I want:
leg.txt1 <- paste("Based upon:\n", ": 75%\n", ": 25%", sep = "")
grid.text(leg.txt1, 0.5, 0.5)
# This paste doesn't work due to the expression statements:
leg.txt2 <- paste("Based upon:\n", expression(^35*Cl), ": 75%\n",
expression(^37*Cl), ": 25%", sep = "")
# This doesnt' produce an error, but doesn't produce what is wanted either,
# as the expression is taken (almost) literally:
leg.txt3 <- paste("Based upon:\n", expression(""^35*Cl), ": 75%\n",
expression(""^37*Cl), ": 25%", sep = "")
grid.text(leg.txt3, 0.5, 0.3)
>From watching the help list, I know parsing things can be tricky.
TIA, Bryan
> sessionInfo()
R version 2.7.1 (2008-06-23)
i386-apple-darwin8.10.1
locale:
en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] datasets grid grDevices graphics stats utils methods
[8] base
other attached packages:
[1] fastICA_1.1-9 DescribeDisplay_0.1.3 ggplot_0.4.2
[4] RColorBrewer_1.0-2 reshape_0.8.0 MASS_7.2-42
[7] pcaPP_1.5 mvtnorm_0.9-0 hints_1.0.1-1
[10] mvoutlier_1.3 robustbase_0.2-8 lattice_0.17-8
[13] rggobi_2.1.9 RGtk2_2.12.5-3
More information about the R-help
mailing list