Displaying 20 results from an estimated 8000 matches similar to: "substitute and expression (Peter Dalgaard)"
2007 Jul 16
2
substitute and expression
Hi,
I'm trying to understand whether the use of substitute() is
appropriate/documented for plotmath annotation. The following two
calls give the same results:
> plot(1:10, main = expression(alpha == 1))
> do.call(plot, list(1:10, main = expression(alpha == 1)))
But not these two:
> plot(1:10, main = substitute(alpha == a, list(a = 2)))
> do.call(plot, list(1:10, main =
2009 Jun 03
1
Would like to add this to example for plotmath. Can you help?
Greetings:
I would like comments on this example and after fixing it up, I need
help from someone who has access to insert this in R's help page for
plotmath.
I uploaded a drawing
http://pj.freefaculty.org/R/Normal-2009.pdf
that is created by the following code
http://pj.freefaculty.org/R/Normal1_2009_plotmathExample.R
This will be a good addition to the plotmath help page/example.
2009 Sep 02
2
combining grid.text, expression and variables
Dear R-users,
I am trying to use the grid.text and expression functions to display
several character strings and plotmath text on a viewport. Some strings
can include a variable portion (PI.limits in the following example),
which I thought could be implemented by combining the bquote and the
expression functions. Unfortunately, my expressions do not seem to be
evaluated. I would greatly
2007 Dec 30
2
Symbolic substitution in parallel; use infinity symbol?
I'd like to be able to modify axlab in (C) below so that 'Inf'
is replaced by the infinity symbol.
y <- rnorm(40)
breaks <- c(-Inf, -1, 1, Inf)
x <- cut(y, breaks=breaks)
plot(unclass(x), y, xaxt="n", xlab="")
## A: The following gives the axis labels "(-Inf, 1]", etc.
axis(1, at=1:3, labels=expression("(-Inf,-1]", "(-1,1]",
2010 May 18
1
substitute, expression and factors
Dear list,
I am puzzled by this,
substitute(expression(x), list(x = factor(letters[1:2])))
# expression(1:2)
Why do I get back the factor levels inside the expression and not the
labels? The following work as I expected,
substitute(expression(x), list(x = letters[1:2]))
# expression(c("a", "b"))
substitute(x, list(x = factor(letters[1:2])))
# [1] a b
# Levels: a b
2010 Jul 06
1
plotmath vector problem; full program enclosed
Here's another example of my plotmath whipping boy, the Normal distribution.
A colleague asks for a Normal plotted above a series of axes that
represent various other distributions (T, etc).
I want to use vectors of equations in plotmath to do this, but have
run into trouble. Now I've isolated the problem down to a relatively
small piece of working example code (below). If you would
2004 Apr 14
1
ltext, plotmath, and substitute
I am interested to use plotmath functions within a panel function but am having
some problems getting the code right. Within each panel I am plotting the data,
fitting a regression line, and would like to print the regression equation.
Here is a trivial example of what I'd like to do:
# generate simple data
tmp.df <- data.frame(id = rep(1:4, each=4),
time = rep(1:4, 4),
das =
2005 Oct 01
2
Multiple expressions, when using substitute()
expression() accepts multiple expressions as arguments, thus:
plot(1:2, 1:2)
legend("topleft",
expression(y == a * x^b,
"where "* paste(y=="wood; ",
x=="dbh")))
Is there a way to do this when values are to be substituted
for a and b? i.e., the first element of the legend argument
to legend() becomes,
2008 Apr 02
1
Trouble combining plotmath, bquote, expressions
I'm using R-2.6.2 on Fedora Linux 9.
I've been experimenting with plotmath.
I wish it were easier to combine expressions in plotmath with values
from the R program itself. There are two parameters in the following
example, the mean "mymean" and standard deviation "mystd". I am able
to use bquote to write elements into the graph title like
mu = mymean
and R will
2010 Feb 02
2
character variables in substitute()
In trying to create a plotmath expression for plot labeling, such as
R = 6, beta = 15
where I want beta to be the Greek beta and, possibly, R in italics (like one
would get in an explicit expression. The reason for this is that I want to
write a string builder function that takes vectors of variable names and
their values and return a plotmath expression for labeling a plot. One
approach I
2007 Nov 15
2
Using plotmath expressions in lattice key text
Folks:
delta <- 1:5
I would like to put 5 separate lines of text of the form "10 %+-% delta[i]"
into a lattice key legend, where ""%+-%" is the plotmath plus/minus symbol
and delta[i] is the ith value of delta.
The construct:
lapply(delta,function(d)bquote(10%+-%.(d)))
appears to produce a list of expressions of the correct form, and, indeed,
if I assign the above
2009 Oct 19
1
How do I wrap a long mixed text/math expression in an axis label?
I would like to wrap a y-axis label onto two lines. My label is an expression
containing both text and math symbols. I have looked at plotmath,
strsplit(), strwrap(), deparse(), do.call(), substitute() and bquote().
Based on previous posts, I can get plain text to wrap. However, when I try
these methods on my label, the exact string is returned, rather than
evaluating the math symbols.
My
2009 Jan 27
1
Plotmath and line breaks in long annotations for plots
I'm trying to combine multi-line text and math annotations on a plot
and am not having much luck. I looked at various suggestions in the
archives, but I cannot coerce any of them to do what I want. I'm
beginning (finally?!) to think that there is an entirely better
approach than the one I have tried.
The essential problem is that line breaks (\n) don't seem to behave
the way I
2008 Apr 08
2
plotmath "overstrikes" in output on a Linux system
I've been testing plotmath. But I'm getting some funny output one one
computer. The problem is that characters are 'jumbled' and overstrike
when symbols are introduced.
Sample code:
mu <- 440.0
sigma <- 12.5
myx <- seq( mu - 4*sigma, mu+ 4*sigma, length.out=500)
myDensity <- dnorm(myx,mean=mu,sd=sigma)
# Here's one way to retrieve the values of mu and sigma and
2009 Aug 12
2
Plotting sigma symbol with unicode and turning into pdf
Paul,
You solution worked out really well when I ran my code in R. However, when I try to turn the plot into a pdf, the unicode string no longer seems to function and instead of the sigma symbol there are just two periods (See example code below).
The following is the code working in the R environment just like I want it to look:
set.seed(1)
Data=rnorm(100,sd=10000)
plot(density(Data))
2011 Jun 02
2
plotmath: paste string and expression [from a vector of expressions]
Dear all,
I have a vector of expressions and would like to "paste" some string to it before using it in a plot:
vars <- vector("expression", 2)
vars[1] <- expression(alpha)
vars[2] <- expression(beta)
plot(0, 0, main=substitute(bold("Foo" ~~ VAR), list(VAR=vars[2]) ))
Although I tried hard, I just can't figure out how to solve this. The title should be
2023 Jun 08
2
need help with plotmath and/or plotting unicode characters
R 4.2.3
OS X
Colleagues
This should be easy -- but not for me.
I want to plot text similar to this:
N ? XX: YY
where XX can be either 1 or 50 and YY is an integer
I envision that there would be two solutions:
UNICODE: If I can generate "?" via unicode, the problem is solved:
mtext(side=3, paste0("N ", UNICODE, " ", XX, ": ", YY))
PLOTMATH:
2010 Jan 25
2
Two == expressions in bquote
Hi,
I want to put text on a plot containing something like: a = b^2 = <squared numeric value of b> using bquote.
Example:
mu = 5
plot(1:10,1:10)
text(2,8, bquote(delta == mu^2)) # This works
text(2.5,8, bquote(phantom(0) == .(mu^2))) # but is unpredictable
text(2,8, bquote(delta == mu^2 == .(mu^2))) # This doesn't work
The last text function returns the error:
2005 Nov 18
1
challenge: using 'subset = <computed>' inside function ..
I've been asked by someone else whom I originally taught
`` to just work with substitute() and then all will be fine'' ...
But it looks to me that I've been caught here.
Is it possible to make this work along the way we thought it should?
1) Inside a function, say tst() with the 'formula' and a 'data' argument,
2) call another modeling function using
2010 Aug 01
3
Constructing arguments for plotmath
Colleagues,
I am encountering difficulty adding formatted text to a graphic. Specifically, I want to add a superscript in the middle of a text string but I would like to format the text string on the fly. The commands:
plot(1,1)
ARG <- bquote('TEXT'^'\u00ae')
mtext(ARG, line=-2, side=1)
yield the desired output.
However, my goal is to paste together a string, then pass