Matthew Pettis
2009-Jan-16 21:19 UTC
[R] Barchart in lattice package: controlling order of bars in plot and color of a selected bar
Hi, I'm using the lattice function 'barchart' to make a series of 4 histograms. Currently, the y-axis values are graphed in order of the y-axis variable. I'd like to have the y-axis values sorted in ascending order of the x-axis values so that the longest bar horizontally is on top of the graph (in it's seciton) and the shortest bar is on the bottom. I can do this in 'barplot' with normal graphics; how can I do this in the lattice barchart function? In addition, i use the 'col' parameter in 'barplot' to make one particular value be a different color than the rest. Is this sort of control available in lattice's barchart? I didn't see it when reading the documentation. Thanks, Matt ### Regular barplot code that works # w02-08 ar pre-sorted in descending "Sum" oder, # "barcolor" column has names of colors to use. opar <- par(mfrow=c(1,4)) barplot(w02[,"Sum"], horiz=T, col=w02[,"barcolor"], names.arg=w02[,"sts.dist"], main="2002") barplot(w04[,"Sum"], horiz=T, col=w04[,"barcolor"], names.arg=w04[,"sts.dist"], main="2004") barplot(w06[,"Sum"], horiz=T, col=w06[,"barcolor"], names.arg=w06[,"sts.dist"], main="2006") barplot(w08[,"Sum"], horiz=T, col=w08[,"barcolor"], names.arg=w08[,"sts.dist"], main="2008") ### Attempt with lattice # work contains w02-08 stacked on top of each other barchart(sts.dist[order(Sum),] ~ Sum | year, data=work, layout=c(4,1), main="Ranking of best turnout by SD")
Seemingly Similar Threads
- [LLVMdev] [llvmdev] Specifying / modeling copying semantics in more detail
- Re: dumpcore changes -- [Xen-changelog] [xen-unstable] In this patch, the xc_domain_dumpcore_via_callback() in xc_core.c of
- Writing unit tests - how to test re-orderable blocks...
- Writing unit tests - how to test re-orderable blocks...
- Convert plugin mbox to maildir has no effect