Hi Bert, I am indeed creating a mathematical expression, but ?plotmath doesn't cover how to do such a vectorized substitution. Best, Wolfgang -----Original Message----- From: Bert Gunter [mailto:bgunter.4567 at gmail.com] Sent: Tuesday, 26 March, 2019 15:52 To: Viechtbauer, Wolfgang (SP) Cc: r-help mailing list Subject: Re: [R] Substitution in expressions I believe you're going about this the wrong way. You seem to want mathematical expressions. Fot this, see ?plotmath. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Mar 26, 2019 at 6:28 AM Viechtbauer, Wolfgang (SP) <wolfgang.viechtbauer at maastrichtuniversity.nl> wrote: Hi All, I am trying to create a vector of expressions, where the elements in the expressions are contained in other vectors (i.e., they should be substituted). I made some attempts with substitute() and bquote(), but couldn't get this to work. My solution so far is: base <- 1:5 expo <- c(2,2,3,3,4) exvec <- as.expression(unname(mapply(function(x,y) bquote(.(x)^.(y)), base, expo))) plot(NA, NA, xlim=c(0,6), ylim=c(0,2)) text(1:5, 1, exvec) Any ideas how I could get this to work with substitute() and/or bquote()? Best, Wolfgang
Perhaps something like this (apologies if beating a dead horse): plot(NA,NA, xlim = c(-1,5),ylim = c(-1,5), xlab = "", ylab = "") for(i in 1:3) text(i,i,labels =bquote(2^.(i))) Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Mar 26, 2019 at 8:27 AM Viechtbauer, Wolfgang (SP) < wolfgang.viechtbauer at maastrichtuniversity.nl> wrote:> Hi Bert, > > I am indeed creating a mathematical expression, but ?plotmath doesn't > cover how to do such a vectorized substitution. > > Best, > Wolfgang > > -----Original Message----- > From: Bert Gunter [mailto:bgunter.4567 at gmail.com] > Sent: Tuesday, 26 March, 2019 15:52 > To: Viechtbauer, Wolfgang (SP) > Cc: r-help mailing list > Subject: Re: [R] Substitution in expressions > > I believe you're going about this the wrong way. You seem to want > mathematical expressions. Fot this, see ?plotmath. > > Cheers, > Bert > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along and > sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > On Tue, Mar 26, 2019 at 6:28 AM Viechtbauer, Wolfgang (SP) < > wolfgang.viechtbauer at maastrichtuniversity.nl> wrote: > Hi All, > > I am trying to create a vector of expressions, where the elements in the > expressions are contained in other vectors (i.e., they should be > substituted). I made some attempts with substitute() and bquote(), but > couldn't get this to work. My solution so far is: > > base <- 1:5 > expo <- c(2,2,3,3,4) > exvec <- as.expression(unname(mapply(function(x,y) bquote(.(x)^.(y)), > base, expo))) > > plot(NA, NA, xlim=c(0,6), ylim=c(0,2)) > text(1:5, 1, exvec) > > Any ideas how I could get this to work with substitute() and/or bquote()? > > Best, > Wolfgang >[[alternative HTML version deleted]]
I initially had a loop, but wanted something vectorized (the vector of expressions is being used as an argument in a function call). But I am happy with sticking to mapply() (plus the slight simplification suggested by Peter Dalgaard). Best, Wolfgang -----Original Message----- From: Bert Gunter [mailto:bgunter.4567 at gmail.com] Sent: Tuesday, 26 March, 2019 17:43 To: Viechtbauer, Wolfgang (SP) Cc: r-help mailing list Subject: Re: [R] Substitution in expressions Perhaps something like this (apologies if beating a dead horse): plot(NA,NA, xlim = c(-1,5),ylim = c(-1,5), xlab = "", ylab = "") for(i in 1:3)? text(i,i,labels =bquote(2^.(i))) Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Mar 26, 2019 at 8:27 AM Viechtbauer, Wolfgang (SP) <wolfgang.viechtbauer at maastrichtuniversity.nl> wrote: Hi Bert, I am indeed creating a mathematical expression, but ?plotmath doesn't cover how to do such a vectorized substitution. Best, Wolfgang -----Original Message----- From: Bert Gunter [mailto:bgunter.4567 at gmail.com] Sent: Tuesday, 26 March, 2019 15:52 To: Viechtbauer, Wolfgang (SP) Cc: r-help mailing list Subject: Re: [R] Substitution in expressions I believe you're going about this the wrong way. You seem to want mathematical expressions. Fot this, see ?plotmath. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Mar 26, 2019 at 6:28 AM Viechtbauer, Wolfgang (SP) <wolfgang.viechtbauer at maastrichtuniversity.nl> wrote: Hi All, I am trying to create a vector of expressions, where the elements in the expressions are contained in other vectors (i.e., they should be substituted). I made some attempts with substitute() and bquote(), but couldn't get this to work. My solution so far is: base <- 1:5 expo <- c(2,2,3,3,4) exvec <- as.expression(unname(mapply(function(x,y) bquote(.(x)^.(y)), base, expo))) plot(NA, NA, xlim=c(0,6), ylim=c(0,2)) text(1:5, 1, exvec) Any ideas how I could get this to work with substitute() and/or bquote()? Best, Wolfgang