Re: [R] curvedarrow (some graphics problem)
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? -- View this message in context: http://www.nabble.com/curvedarrow-%28some-graphics-problem%29-tp24158796p24196544.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] curvedarrow (some graphics problem)
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.
Re: [R] curvedarrow (some graphics problem)
baptiste auguie-4 wrote: Hi, Grid offers several functions to help drawing such graphs, see Paul Murrell's Can R Draw Graphs? (useR! 2006) I came up with this, as a quick example, vp - viewport( x = unit(0, npc), y = unit(0, npc), just = c(left, bottom), xscale = c(-1, 1) , yscale = c(-1, 1)) Hi, I tried to do the first part. However, it returned with no such function 'viewport' error. Do I have to load some package first? And this is a lot 'more' code than I expected since I am very new to R. It amazes me that R can be so POWERFUL! I will try make your code work and have a look at the page you pointed out. Thank you for you help. Chen -- View this message in context: http://www.nabble.com/curvedarrow-%28some-graphics-problem%29-tp24158796p24178684.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] curvedarrow (some graphics problem)
[quote] grid.text(t, x=0.3, y=unit(-1, line), vp=vp2) Error in valid.units(units) : Invalid unit grid.text(s, 0.8, unit(-1, line), gp=gpar(col=red), vp=vp2) Error in valid.units(units) : Invalid unit[/quote] Hi, I have loaded the [grid] package. It seems that I have to load another package? Thanks -- View this message in context: http://www.nabble.com/curvedarrow-%28some-graphics-problem%29-tp24158796p24178859.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ 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.
Re: [R] curvedarrow (some graphics problem)
On Jun 24, 2009, at 1:21 AM, casperyc wrote: [quote] grid.text(t, x=0.3, y=unit(-1, line), vp=vp2) Error in valid.units(units) : Invalid unit grid.text(s, 0.8, unit(-1, line), gp=gpar(col=red), vp=vp2) Error in valid.units(units) : Invalid unit[/quote] Hi, I have loaded the [grid] package. It seems that I have to load another package? No. Such a need might have been suggested by a function not found error. In this case the details are in the help page for the unit function in grid. The unit parameter was mis-specified. ?unit Try: grid.text(t, x=0.3, y=unit(-1, lines), vp=vp2) -- grid.text(s, 0.8, unit(-1, lines), gp=gpar(col=red), vp=vp2) David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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.
Re: [R] curvedarrow (some graphics problem)
You're right, I meant to write linesnot line. The strange thing is, although line isn't listed in ?unit, it doesn't return an error on my machine, unit(-1, line) [1] -1line unit(-1, lines) [1] -1lines Reading from http://svn.r-project.org/R/trunk/src/library/grid/src/unit.c line is listed as a pseudonym, so I guess it is a valid unit after all. sessionInfo() R version 2.9.0 (2009-04-17) i386-apple-darwin8.11.1 locale: en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8 attached base packages: [1] datasets stats grid ( 2.9.0 ) graphics grDevices utils methods base Best, baptiste David Winsemius wrote: On Jun 24, 2009, at 1:21 AM, casperyc wrote: [quote] grid.text(t, x=0.3, y=unit(-1, line), vp=vp2) Error in valid.units(units) : Invalid unit grid.text(s, 0.8, unit(-1, line), gp=gpar(col=red), vp=vp2) Error in valid.units(units) : Invalid unit[/quote] Hi, I have loaded the [grid] package. It seems that I have to load another package? No. Such a need might have been suggested by a function not found error. In this case the details are in the help page for the unit function in grid. The unit parameter was mis-specified. ?unit Try: grid.text(t, x=0.3, y=unit(-1, lines), vp=vp2) -- grid.text(s, 0.8, unit(-1, lines), gp=gpar(col=red), vp=vp2) David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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. -- _ Baptiste AuguiƩ School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ 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.
Re: [R] curvedarrow (some graphics problem)
I get: unit(-1, line) Error in valid.units(units) : Invalid unit unit(-1, lines) [1] -1lines I have an older version of R (2.8.1) and of grid (2.8.1). The source for grid 2.8.1 does not have pseudonyms. http://svn.r-project.org/R/branches/R-2-8-branch/src/library/grid/src/unit.c -- David On Jun 24, 2009, at 9:48 AM, baptiste auguie wrote: You're right, I meant to write linesnot line. The strange thing is, although line isn't listed in ?unit, it doesn't return an error on my machine, unit(-1, line) [1] -1line unit(-1, lines) [1] -1lines Reading fromhttp://svn.r-project.org/R/trunk/src/library/grid/src/unit.c line is listed as a pseudonym, so I guess it is a valid unit after all. sessionInfo() R version 2.9.0 (2009-04-17) i386-apple-darwin8.11.1 locale: en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8 attached base packages: [1] datasets stats grid ( 2.9.0 ) graphics grDevices utils methods base Best, baptiste David Winsemius wrote: On Jun 24, 2009, at 1:21 AM, casperyc wrote: [quote] grid.text(t, x=0.3, y=unit(-1, line), vp=vp2) Error in valid.units(units) : Invalid unit grid.text(s, 0.8, unit(-1, line), gp=gpar(col=red), vp=vp2) Error in valid.units(units) : Invalid unit[/quote] Hi, I have loaded the [grid] package. It seems that I have to load another package? No. Such a need might have been suggested by a function not found error. In this case the details are in the help page for the unit function in grid. The unit parameter was mis-specified. ?unit Try: grid.text(t, x=0.3, y=unit(-1, lines), vp=vp2) -- grid.text(s, 0.8, unit(-1, lines), gp=gpar(col=red), vp=vp2) David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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. -- _ Baptiste AuguiƩ School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ 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. David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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.
Re: [R] curvedarrow (some graphics problem)
Hi, Grid offers several functions to help drawing such graphs, see Paul Murrell's Can R Draw Graphs? (useR! 2006) I came up with this, as a quick example, 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.8, y=0.5, gp=gpar(col=NA), default.units = npc, name=h2, vp=vp) grid.text(t, x=0.3, y=unit(-1, line), vp=vp2) grid.text(s, 0.8, unit(-1, line), gp=gpar(col=red), vp=vp2) grid.curve(grobX(h2, 180), grobY(h2, 180), grobX(h1, 180), grobY(h1, 180), shape=1, ncp=10, square=FALSE, curvature=1, arrow=arrow()) upViewport() HTH, baptiste casperyc wrote: Hi there, I just wonder how to draw this kind of picture... http://www.nabble.com/file/p24158796/b.jpg http://www.nabble.com/file/p24158796/a.jpg and this is what i have done % library(shape) library(diagram) curve(sin(x),bty=n,-8,8,yaxt=n,ylab=,xaxt=n,type=n,xlab=) axis(1,labels=F,at=seq(-8,8,1)) curvedarrow(from=c(-4,-1), to=c(4,-1),curve=-0.035,arr.pos=1,lwd=1) text(0,-0.62,substitute(mu(s,t))) axis(1,labels=s,at=-4) axis(1,labels=t,at=4) % is there any easier way or the most proper way to draw these to graphs? Thanks in advance! Chen __ 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.
Re: [R] curvedarrow (some graphics problem)
Hi baptiste auguie wrote: Hi, Grid offers several functions to help drawing such graphs, see Paul Murrell's Can R Draw Graphs? (useR! 2006) The recent article in The R Journal http://journal.r-project.org/2009-1/RJournal_2009-1_Murrell.pdf might also be useful. Paul I came up with this, as a quick example, 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.8, y=0.5, gp=gpar(col=NA), default.units = npc, name=h2, vp=vp) grid.text(t, x=0.3, y=unit(-1, line), vp=vp2) grid.text(s, 0.8, unit(-1, line), gp=gpar(col=red), vp=vp2) grid.curve(grobX(h2, 180), grobY(h2, 180), grobX(h1, 180), grobY(h1, 180), shape=1, ncp=10, square=FALSE, curvature=1, arrow=arrow()) upViewport() HTH, baptiste casperyc wrote: Hi there, I just wonder how to draw this kind of picture... http://www.nabble.com/file/p24158796/b.jpg http://www.nabble.com/file/p24158796/a.jpg and this is what i have done % library(shape) library(diagram) curve(sin(x),bty=n,-8,8,yaxt=n,ylab=,xaxt=n,type=n,xlab=) axis(1,labels=F,at=seq(-8,8,1)) curvedarrow(from=c(-4,-1), to=c(4,-1),curve=-0.035,arr.pos=1,lwd=1) text(0,-0.62,substitute(mu(s,t))) axis(1,labels=s,at=-4) axis(1,labels=t,at=4) % is there any easier way or the most proper way to draw these to graphs? Thanks in advance! Chen __ 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. -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 p...@stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/ __ 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.
[R] curvedarrow (some graphics problem)
Hi there, I just wonder how to draw this kind of picture... http://www.nabble.com/file/p24158796/b.jpg http://www.nabble.com/file/p24158796/a.jpg and this is what i have done % library(shape) library(diagram) curve(sin(x),bty=n,-8,8,yaxt=n,ylab=,xaxt=n,type=n,xlab=) axis(1,labels=F,at=seq(-8,8,1)) curvedarrow(from=c(-4,-1), to=c(4,-1),curve=-0.035,arr.pos=1,lwd=1) text(0,-0.62,substitute(mu(s,t))) axis(1,labels=s,at=-4) axis(1,labels=t,at=4) % is there any easier way or the most proper way to draw these to graphs? Thanks in advance! Chen -- View this message in context: http://www.nabble.com/curvedarrow-%28some-graphics-problem%29-tp24158796p24158796.html Sent from the R help mailing list archive at Nabble.com. __ 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.