how to make plotmath expression work together with paste

Paul Johnson pauljohn32 at gmail.com
Mon Mar 6 02:30:48 CET 2006


Recent questions about using plotmath have renewed my interest in this question

I want to have expressions take values of variables from the
environment. I am able to use expressions, and I am able to use paste
to put text and values of variables into
plots.  But the two things just won't work together.

Here is some example code that shows what I mean.


plot(NA,xlim=c(0,100),ylim=c(0,100))

#show plot math works
text(16, 22, expression(slope == frac(partialdiff * f(hat(theta)),
     partialdiff * hat(theta))))

# I want to put values of variables into the middle of expressions
 avar1 <- 10

# prove I am able to use paste!
text(40,40, paste("a word",avar1,"other words")

# But I'm completely frustrated by the problem of making paste and
# expression work together.

amath1 <- expression(slope == frac(partialdiff * f(hat(theta)), 
partialdiff * hat(theta)))

# still works
text(10,60,amath1)


# paste breaks math output
text(60,60, paste (amath1, "=" , avar1) )


# Can't paste expression
text(20,30, paste("a word",avar1, expression( partialdiff )))



# paste does not work anymore--value of avar1 not replaced
text(50,80, expression(paste("slope" == frac(partialdiff *
f(hat(theta)),partialdiff * hat(theta)), avar1)))

n<-12

# This does get the avar1 value in the string and put it in, but it
# piles the labels on top of each other. Wish they went side by side
 text(12, 15, labels=c(expression(bar(x) == sum(frac(x[i], n), i==1,
)), paste("gamma =",avar1)),cex = .8)




--
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas



More information about the R-help mailing list