[R] Single plot multiple levels in x?

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Aug 31 15:50:35 CEST 2007


What about something like:


library("lattice")
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", "PctRecurr")
mydf$State <- factor(mydf$State)

Then you can ask

xyplot(PctRecurr ~ Position | State, data=mydf, layout= c(5,1))

or perhaps:

xyplot(PctRecurr ~ Position | State, data=mydf, layout= c(5,1), 
scales=list(axs='i'))


Uwe Ligges





Richard Yanicky wrote:
> 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