[R] xyplot: adjusting the scale (min, max & tick)

Peter Ehlers ehlers at ucalgary.ca
Thu Jan 7 14:04:07 CET 2010


Jay wrote:
> Perfect, that piece of code did exactly what I wanted. However, I stumpled
> upon a new problem, now my data is plotted on a totally wrong scale. The
> y-values are all between 160k and 500k, BUT now with that option I find that
> the plots are between 0 and 50 (?!?). What did I do wrong?
> 
> This plots the data OK, even thoug it should be between  160k and 500k on
> the y-scale:
> 
> xyplot(data1[,2]+data1[,3]~data1[,1], data = data1,
>         type = "l",
>         xlab = "x",
>         ylab = "y",
>         auto.key = list(space="top", lines = T, points = F, text=c("text1",
> text2")),
>         par.settings = simpleTheme(lty = c(1,2)),
>         scales=list(
>           x=list(alternating=FALSE,tick.number = 11),
>           y=list(limits=c(0,50))
>         )     
>         )   
> 
> If I remove the " y=list(limits=c(0,50))" the dat is plotted as it should.
> 
You probably want something like

   y = list(at = seq(100, 200, 25), limits = c(100, 200))

Try this:
x <- 1:20
y1 <- rnorm(20)*1e3
y2 <- rnorm(20)*1e3
xyplot(y1 + y2 ~ x, type='l',
   scales = list(y = list(
      at = seq(-300,400,100),
      limits = c(-500,500)))
)

# or, you could use the ylim argument instead of 'limits=':
xyplot(y1 + y2 ~ x, type='l', ylim = c(-500, 500),
   scales = list(y = list(
      at = seq(-300,400,100)))
)

  -Peter Ehlers

> 
> 
> Peter Ehlers wrote:
>> Have a look at the 'scales' argument. For example:
>>
>> # default plot
>> xyplot(Sepal.Length ~ Petal.Length | Species, data = iris)
>>
>> # modified plot
>> xyplot(Sepal.Length ~ Petal.Length | Species, data = iris,
>>      scales=list(y=list(at=c(-5,0,5,10), limits=c(-5,10))))
>>
>>   -Peter Ehlers
>>
>> Jay wrote:
>>> Hi,
>>>
>>> I'm terribly sorry but it seems it cannot figure this one out by
>>> myself so, please, if somebody could help I would be very grateful.
>>> So, when I plot with xyplot() I get an y-axis that is very ugly...
>>> starting from a random number and having so many ticks that it becomes
>>> unreadable.
>>>
>>> How do I tell xyplot how to draw the axis? E.g., start from 100, end
>>> at 200 with 25 units between ticks/labels?
>>> Can somebody give me an example?
>>>
>>> Thanks!
>>>
>>> ______________________________________________
>>> 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.
>>>
>>>
>> -- 
>> Peter Ehlers
>> University of Calgary
>> 403.202.3921
>>
>> ______________________________________________
>> 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.
>>
>>
> 

-- 
Peter Ehlers
University of Calgary
403.202.3921



More information about the R-help mailing list