[R] Reorder the x-axis using lattice

Richard.Cotton at hsl.gov.uk Richard.Cotton at hsl.gov.uk
Mon Mar 31 15:07:40 CEST 2008


>    Is there a way to reorder the xaxis using lattice. Using the 
> following data, the x-axis is ordered as BP GH MH PF RE RP SF VT but
> I would like the x-axis to be ordered as PF RP BP GH VT SF RE MH.
> 
>     Kön         Skalor     Tillfälle Medelvärde
> 1  Kvinnor     BP 1-inskrivning   36.45283
> 2  Kvinnor     GH 1-inskrivning   38.62255
> 3  Kvinnor     MH 1-inskrivning   62.88889
> 4  Kvinnor     PF 1-inskrivning   39.80710

>   bwplot(Medelvärde ~ Skalor| Kön , kt, panel = "panel.superpose",
>        groups = Tillfälle,scales = list(x = list(rot = 45),cex=0.7,
> alternating=2),
> ...

When the x-axis is a factor, bwplot plots in order of the factor levels. 
You'll need to explicitly set the levels in your data frame:

Skalor <- factor(c("BP", "GH", "MH", "PF", "RE", "RP", "SF", "VT", "BP", 
"GH", "MH", "PF", "RE", "RP", "SF", "VT"), levels=c("PF", "RP", "BP", 
"GH", "VT", "SF", "RE", "MH"))
kt <- data.frame(Kon=Kon, Skalor=Skalor, ...)
bwplot(...) #as before

Regards,
Richie.

Mathematical Sciences Unit
HSL


r-help-bounces at r-project.org wrote on 31/03/2008 11:05:18:

> Dear list,
> 

> 5  Kvinnor     RE 1-inskrivning   41.50943
> 6  Kvinnor     RP 1-inskrivning   22.22222
> 7  Kvinnor     SF 1-inskrivning   59.19811
> 8  Kvinnor     VT 1-inskrivning   34.84568
> 9  Kvinnor     BP 2-utskrivning   43.14815
> 10 Kvinnor     GH 2-utskrivning   44.11321
> 11 Kvinnor     MH 2-utskrivning   77.22222
> 12 Kvinnor     PF 2-utskrivning   44.74280
> 13 Kvinnor     RE 2-utskrivning   68.95425
> 14 Kvinnor     RP 2-utskrivning   39.90385
> 15 Kvinnor     SF 2-utskrivning   64.62264
> 16 Kvinnor     VT 2-utskrivning   51.97531
> 
> 

>        panel.groups = "panel.linejoin",lty=c(1:3),lwd=3,
> col=c("steelblue","grey50","green4"),
>        ylab = list(label = "skalpoäng (0-100)", cex = 0.8),
>        xlab = list(label = "skalor", cex = 0.8),
>        key = list(lines = 
> Rows(list(col=c("steelblue","grey50","green4"),lty=c(1:3)),
>                 c(1:3, 0)),cex=0.8,text = list(lab = as.
> character(unique(kt$Tillfälle))),
>                   columns = 2, title = "SF-36: Skalpoäng för 
> respektive kön vid 3 mättillfälle ",
>                   cex.title=0.9))
> 
>   Thanks in advance,
>   Tom
> 
> 
> ---------------------------------
> 
> Jämför pris på flygbiljetter och hotellrum: http://shopping.yahoo.
> se/c-169901-resor-biljetter.html
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.

------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:21}}



More information about the R-help mailing list