[R] Single plot multiple levels in x?

Greg Snow Greg.Snow at intermountainmail.org
Fri Aug 31 20:55:47 CEST 2007


Try this code (with the mydf that you generate below):

library(TeachingDemos)

plot( c(0,5), c(0,1), xlab='State', ylab='ylab', axes=FALSE, type='n' )
axis(1, at= (1:5) - 0.5, labels=paste('state',1:5))
box()

for(i in 1:5){
	with( subset(mydf, State==i),
	  subplot( plot(Position, `Pct Recurr`, col=i,
		yaxt=ifelse( i==1, 's', 'n' ), ylab='',xlab='',
cex.axis=0.5),
		x=c(i-1,i), y=c(0,1) )
	)
}


Is that close to what you want? 


-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
 
 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Richard Yanicky
> Sent: Thursday, August 30, 2007 11:37 AM
> To: Uwe Ligges
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] Single plot multiple levels in x?
> 
> Uwe,
> 
> 
> Here is some code to create some data then a plot (The plot 
> was done in another package). The plot is included only to 
> reference the structure of the x-axis. I can't get R to do 
> something similar.
> 
> 
> State <- seq (1:5);
> posi <- seq (0.5,62525,199.233)
> 
> mydf<-NULL;
> 
> for ( i in 1:5) {
> 
> df1<-data.frame(i,posi);
> 
> mydf <- rbind(mydf,df1); }   
> 
> myy<-rep(-100.01:100.01,length=nrow(mydf));
> 
> mydf<-cbind(mydf,myy);
> 
> names(mydf) <- c("State","Position","Pct Recurr");
> 
> 
> 
> 
> I would like to somehow:
> 
> 
> plot(c(mydf[,1],mydf[,2]),mydf[,3]) and end up with the 
> nested structure on the x-axis.
> 
> Thanks,
> 
> Richard
> 
> 
> -----Original Message-----
> >From: Uwe Ligges <ligges at statistik.uni-dortmund.de>
> >Sent: Aug 30, 2007 10:50 AM
> >To: Richard Yanicky <ryanicky at mindspring.com>
> >Cc: r-help at stat.math.ethz.ch
> >Subject: Re: [R] Single plot multiple levels in x?
> >
> >
> >
> >Richard Yanicky wrote:
> >> Uwe,
> >> 
> >> I have looked into lattice and can't seem to make this 
> work. I can easily make multiple panels but this isn't what I 
> am looking to do. Any suggestions on which functions to use? 
> the axis function seems a natural place to start but I still 
> can't seem to make it happen.
> >
> >If lattice is not what you want, I do not understand what 
> you mean. Can 
> >you give a more elaborated example, please?
> >
> >Uwe
> >
> >
> >> 
> >> HELP!
> >> 
> >> 
> >> Richard
> >> 
> >> -----Original Message-----
> >>> From: Uwe Ligges <ligges at statistik.uni-dortmund.de>
> >>> Sent: Aug 30, 2007 5:59 AM
> >>> To: Richard Yanicky <ryanicky at mindspring.com>
> >>> Cc: r-help at stat.math.ethz.ch
> >>> Subject: Re: [R] Single plot multiple levels in x?
> >>>
> >>>
> >>>
> >>> Richard Yanicky wrote:
> >>>> Plotting with 2 x axis?
> >>>>
> >>>>
> >>>> One axis inside another, for example salary within state,
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> 1-50     |     50 - 100 |  100+   |   1- 50 | 50 -100 | 
> 100+ | ...  repeated bins for salary
> >>>>                AL                           !            
>    AR                     ......  more states
> >>>
> >>> Sounds like the lattice package does exactly what you want, but 
> >>> without any reproducible example.....
> >>>
> >>> Uwe Ligges
> >>>
> >>>
> >>>
> >>>> The values are all stored with a single data frame. I have tried 
> >>>> different things with the axis function and done many 
> searches for 
> >>>> plotting. Can't find a direct reference
> >>>>
> >>>>
> >>>> Thanks.
> >>>>
> >>>> Richard
> >>>>
> >>>> ______________________________________________
> >>>> R-help at stat.math.ethz.ch 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.
> >> 
>



More information about the R-help mailing list