[R] curvedarrow (some graphics problem)

Paul Murrell paul at stat.auckland.ac.nz
Tue Jun 23 23:20:26 CEST 2009


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 at 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
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/




More information about the R-help mailing list