Try using the I() function in the call to data.frame. E.g., > d <- data.frame(X=1:3, Y=1:3, Substance=I(expression(H[2]*O, H[2] * O[2], H*S*O[4]))) > with(d, {plot(X,Y,type="n",xlim=c(0,4)); text(X, Y, Substance)})
Bill Dunlap TIBCO Software wdunlap tibco.com On Sat, Mar 21, 2020 at 1:45 AM Troels Ring <tr...@gvdnet.dk> wrote: > Dear friends - I have some old data of chemical results and want to > annotate > the points with chemical formula. If I just do > > ID <- c("HCl 7","HCl 5.25","HCl 3.5","HCL 7 no Na","HCl 3.5 No Na", > > "HSO4 7 no Na", > > "HNO3 7 No Na") > > I can make a data.frame like > > DD <- data.frame(x=1:7,ID) > > > > and plotting works fine. > > But if I try to format sulfuric acid and nitric acid like > > ID <- c("HCl 7","HCl 5.25","HCl 3.5","HCL 7 no Na","HCl 3.5 No Na", > > expression(paste(HSO[4]," 7 no Na")), > > expression(paste(HNO[3]," 7 No Na"))) > > > > DD <- data.frame(x=1:7,ID) > > Elicits an error > > Error in as.data.frame.default(x[[i]], optional = TRUE) : > > cannot coerce class '"expression"' to a data.frame > > and plotting is prohibited - so how is this bypassed? > > > > I'm on Windows 10, > > R version 3.6.1 (2019-07-05) > > > > All best wishes > > Troels Ring, MD > > Aalborg, Denmark > > > This email has been scanned by BullGuard antivirus protection. > For more info visit www.bullguard.com > < > http://www.bullguard.com/tracking.aspx?affiliate=bullguard&buyaffiliate=smt > p&url=/ > <http://www.bullguard.com/tracking.aspx?affiliate=bullguard&buyaffiliate=smtp&url=/>> > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. > [[alternative HTML version deleted]] ______________________________________________ R-help@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.