[R] Lattice graph help

Rainer Hurling rhurlin at gwdg.de
Mon Nov 21 22:46:10 CET 2011


I just tried a litte bit with your dataset and hope to get a solution as 
wanted ;-)

On 21.11.2011 21:55 (UTC+1), Andrew McFadden wrote:
> Hi all
> I hope you might help me with some aspects of producing a graph in lattice. There are three things I have struggling with and that is: 1. to separate the horizontal box rows from each other; 2. to change the colour of the horizontal and vertical strips to white; and 3. to place the axes labels on the left y axes and on the bottom x axes. I would really appreciate some help. I have put the following example together. I tried "between=list(y=c(1))" to try and separate the horizontal box rows but perhaps I have not used this correctly. I tried to use the following to place the labels on the left y axes "scales=list(y=list(alternating=c(1))" but again perhaps I didn't use this correctly.

> library(lattice)
> library(latticeExtra)
> n=as.factor(c(1:5,1:5))
> Breed=as.factor(c(rep("Cow",3),rep("Sheep",3),rep("Goat",2),rep("Yak",2)))
> Test=as.factor(c(rep("Bovine viral diarrhoea",5),rep("Border Disease",5)))
> Titer=as.numeric(c(10,20,30,40, 50,15, 25, 35, 45, 55))
> heif=data.frame(n,Breed, Test, Titer)
> x=barchart( heif[,4]~ heif[,1]| heif[,3]+ heif[,2] ,ylab="titer",
> layout = c(2,2), scales=list(x=list(at=c(seq(0, 60, by = 15)),tick.number=c(5),
> labels=c(seq(0, 60, by = 15))))
> )

# you can use 'heif' more directly like in models
x=barchart( Titer ~ n | Test+Breed, data=heif,
   layout = c(2,4),

   # distance between rows
   between = list(y = c(0.5)),

   # x- and y-lables only onesided, ticks also onesided
   scales = list(x = list(alternating = 1, tck = c(1,0)),
             y = list(alternating = 1, tck = c(1,0))),

   xlab = "count (n)",
   ylab = "titer"
   )

> useOuterStrips(x)

# the best way I found for colouring was in useOuterStrips
useOuterStrips(x,
                strip = strip.custom(bg = "white"),
                strip.left = strip.custom(bg = "white")
                )

Hope this helps,
Rainer Hurling


> Kind regards
> Andrew McFadden MVS BVSc | Veterinary Epidemiologist,
> Investigation and Diagnostic Centre | Biosecurity New Zealand
> Ministry of Agriculture and Forestry | 66 Ward St,  Wallaceville | PO Box 40 742 | Upper Hutt | New Zealand
> Telephone: 64-4-894 5611 | Facsimile: 64-4-894 4973| Mobile: 027-733-1791 | Web: www.maf.govt.nz



More information about the R-help mailing list