This will give you a greek character, see ?plotmath
grid.text(expression(mu*"(s,t)"), 0.5, unit(5, "lines"), vp=vp2)
The following works for me, it may be that you're using an outdated
version of R,
vp <- viewport(
x = unit(0, "npc"),
y = unit(0, "npc"),
just = c("left", "bottom"),
xscale = c(-1, 1) ,
yscale = c(-1, 1))
vp2 <- viewport( # probably not needed but I had trouble placing the xaxis
x = unit(0, "npc"),
y = unit(0.5, "npc"),
just = c("left", "bottom"),
xscale = c(-1, 1) ,
yscale = c(-1, 1))
pdf() # open the pdf device
pushViewport(vp)
grid.xaxis(at=seq(-1, 1, by=0.2), label=FALSE, vp=vp2)
grid.points(x=0.3, y=0.5, gp=gpar(col=NA), default.units = "npc",
name="h1", vp=vp)
grid.points(x=0.7, y=0.5, gp=gpar(col=NA), default.units = "npc",
name="h2", vp=vp)
grid.text("s", x=0.3, y=unit(-1, "lines"), vp=vp2)
grid.text("t", 0.7, unit(-1, "lines"), gp=gpar(col="red"), vp=vp2)
grid.text(expression(mu*"(s,t)"), 0.5, unit(5, "lines"), vp=vp2)
grid.curve(grobX("h2", 180),
grobY("h2", 180),
grobX("h1", 180),
grobY("h1", 180),
shape=1, ncp=10,
square=FALSE,
curvature=.4,
arrow=arrow(angle=20,ends="first") )
upViewport()
dev.off() # close the device
casperyc wrote:
Hi there,
This is now the code
%%%%%
library(grid)
vp <- viewport(
x = unit(0, "npc"),
y = unit(0, "npc"),
just = c("left", "bottom"),
xscale = c(-1, 1) ,
yscale = c(-1, 1))
vp2 <- viewport( # probably not needed but I had trouble placing the xaxis
x = unit(0, "npc"),
y = unit(0.5, "npc"),
just = c("left", "bottom"),
xscale = c(-1, 1) ,
yscale = c(-1, 1))
pushViewport(vp)
grid.xaxis(at=seq(-1, 1, by=0.2), label=FALSE, vp=vp2)
grid.points(x=0.3, y=0.5, gp=gpar(col=NA), default.units = "npc",
name="h1", vp=vp)
grid.points(x=0.7, y=0.5, gp=gpar(col=NA), default.units = "npc",
name="h2", vp=vp)
grid.text("s", x=0.3, y=unit(-1, "lines"), vp=vp2)
grid.text("t", 0.7, unit(-1, "lines"), gp=gpar(col="red"), vp=vp2)
grid.text("mu(s,t)", 0.5, unit(5, "lines"), vp=vp2)
grid.curve(grobX("h2", 180),
grobY("h2", 180),
grobX("h1", 180),
grobY("h1", 180),
shape=1, ncp=10,
square=FALSE,
curvature=.4,
arrow=arrow(angle=20,ends="first") )
upViewport()
%%%%%
for this line:
grid.text("mu(s,t)", 0.5, unit(5, "lines"), vp=vp2)
how do I change "mu(s,t)" to the expression "mu"?
I have tried
grid.text(expression="mu(s,t)", 0.5, unit(5, "lines"), vp=vp2)
grid.text(expression(mu(s,t)), 0.5, unit(5, "lines"), vp=vp2)
both didnt work
AND
when I tried to save the output as PDF file
it returns:
Error in function (name) : Grob 'h2' not found
I have no idea what to do?
______________________________________________
R-help@r-project.org mailing list
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.