Re: [R] problems with Stackpoly, package Plotrix

2009-09-21 Thread Jim Lemon

On 09/21/2009 09:15 AM, Václav Varvařovský wrote:

Dear all,

I am fairly new to package Plotrix and I would like to ask you, if any of
you could help me with following.

a) I don't know how to set up border line width in the Stackpoly function
(seems that lwd from par doesn't work, or at least not in the way I have
written)
b) I don't know, how to rotate the x axis labels (I used srt=45, but same
problem as before).
c) Could anyone clarify to me, what does e.g. col= par(col) stand for in
the usage explanation? Does it somehow change the way I should call such
parameter?
d) the three dots in stackpoly usage are calling other parameters from plot,
however if in plot there are the three dots calling parameters from par, am
I able to call parameters from par directly in stackpoly?

   

Hi Vaclav,
You have identified several missing bits in stackpoly. Let's take them 
one by one.


a) There is no way to specify border width at the moment. stackpoly is a 
fairly new function, and I usually program these with minimal options 
and let the users tell me what is missing. In the modified function 
below, there is a lwd argument that allows the user to specify this.


b) If you want to have angled tick labels, you will have to roll your 
own with text(). First set par(xpd=TRUE), then display the labels, then 
set par(xpd=FALSE). Unfortunately axis() doesn't obey the srt argument.


c) I can't find the reference to col=par(col) in the help page 
(stackpoly uses col=NA). par(col) returns the current drawing color 
(default is black) and would be unlikely to be useful as you would get 
one big black polygon. The default is to use rainbow() to specify the 
colors, or the user can pass one or more colors that will define the 
fill colors for the polygons.


d) I think so. If the ... arguments are after any arguments that plot() 
recognizes, I think they will be passed to par(), but I can't say for sure.


The modified stackpoly function will appear in plotrix 2.7-1.

Jim

stackpoly-function(x,y=NULL,main=,xlab=,ylab=,xat=NA,xaxlab=NA,
 xlim=NA,ylim=NA,lty=1,lwd=1,border=NA,col=NA,staxx=FALSE,stack=FALSE,
 axis4=TRUE,...) {

 ydim-dim(y)
 if(is.null(y[1])) {
  y-x
  ydim-dim(y)
  if(is.null(ydim)) x-1:length(y)
  else x-matrix(rep(1:ydim[1],ydim[2]),ncol=ydim[2])
 }
 if(stack) y-t(unlist(apply(as.matrix(y),1,cumsum)))
 if(is.na(xlim[1])) xlim-range(x)
 if(is.na(ylim[1])) ylim-range(y)
 plot(0,main=main,xlab=xlab,ylab=ylab,xlim=xlim,ylim=ylim,type=n,
  xaxs=i,yaxs=i,axes=FALSE,...)
 box()
 if(is.matrix(y) || is.list(y)) {
  plotlim-par(usr)
  if(is.na(xat[1])) {
   xat-x[,1]
   if(is.na(xaxlab[1])) xaxlab-xat
  }
  if(staxx) staxlab(at=xat,labels=xaxlab)
  else axis(1,at=xat,labels=xaxlab)
  axis(2)
  if(axis4) axis(4)
  if(is.na(col[1])) col=rainbow(ydim[2])
  else if(length(col)ydim[2]) col-rep(col,length.out=ydim[2])
  if(length(lty)ydim[2]) lty-rep(lty,length.out=ydim[2])
  if(length(lwd)ydim[2]) lwd-rep(lwd,length.out=ydim[2])
  for(pline in seq(ydim[2],1,by=-1)) {
   if(pline==1) {
polygon(c(x[1],x[,pline],x[ydim[1]]),
 c(plotlim[3],y[,pline],plotlim[3]),
 border=border,col=col[pline],lty=lty[pline],lwd=lwd[pline])
   }
   else
polygon(c(x[,pline],rev(x[,pline-1])),c(y[,pline],rev(y[,pline-1])),
 border=border,col=col[pline],lty=lty[pline],lwd=lwd[pline])
  }
 }
 else {
  polygon(c(min(x),x,max(x),0),c(0,y,0,0),border=border,col=col,lty=lty,
   lwd=lwd)
  if(is.na(xat[1])) {
   xat-x
   if(is.na(xaxlab[1])) xaxlab-xat
  }
  if(staxx) staxlab(at=xat,labels=xaxlab)
  else axis(1,at=xat,labels=xaxlab)
  axis(2)
  if(axis4) axis(4)
 }
}
__
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] problems with Stackpoly, package Plotrix

2009-09-21 Thread Jim Lemon

On 09/21/2009 09:31 AM, Václav Varvařovský wrote:

xpopis-c(0.9,0.99,0.999)
paste(1 in,round(1/(1-xpopis),1),sep= )
#n as number of subjects is 4
result-c(0.3,0.15,0.4,0.15,0.5,0.1,0.12,0.28,0.45,0.25,0.2,0.1)
stackpoly(x=matrix(nrow=3,ncol=4,xpopis),y=matrix(nrow=3,ncol=4,result,byrow=T),
  xlim=c(0.85,1),ylim=c(0,1),
 xaxlab=paste(1 in,round(1/(1-xpopis),1),sep= ),xat=xpopis,
  col=c(blue,red,green,cyan),
border=gray(0.4),lty=dotted,lwd=0.1,stack=T,srt=45)
   

Hi again,
This gives me a better idea of what you want. If you make your third 
line in the call:


xaxlab=c(,,),xat=xpopis,

and then:

par(xpd=TRUE)
text(c(0.9,0.99,1),c(-0.06,-0.06,0.06),
 c(1 in 10,1 in 100,1 in 1000),srt=45)

I think you will get what you want.

Jim

__
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.