[R] changing settings on a barchart (lattice)
Dieter Menne
dieter.menne at menne-biomed.de
Wed Feb 11 18:47:25 CET 2009
Dimitri Liakhovitski <ld7631 <at> gmail.com> writes:
> I apologize - I never used lattice before, so my question is probably
> very basic - but I just can't find the answer in the archive nor in
> the documentation:
>
> I have a named numeric vector p of 6 numbers (of the type 6 numbers
> with people's names to whom those numbers belong). I want a simple bar
> chart.
>
> I am doing:
>
> library(lattice)
> trellis.par.set(fontsize=list(text=12)) # Changes only axes font
> barchart(~sort(p),main="Text for main",xlab="Text for X axis",
> col=PrimaryColors[3])
>
> It works just fine.
> Question: Where how can I change such things as font size for X axis
> label (below the numbers), font size for Title, value labels (to label
> bars with actual numbers), add grids, etc.?
Finding the right settings in lattice is a bit of intelligent guesswork.
Here my sequence:
0) show.settings() # rather incomplete
1) str(trellis.par.get()) # names are quite rational, so this is 80% success
2) browse Deepayan's book examples
http://lmdvr.r-forge.r-project.org/figures/figures.html
After you got the right settings, keep these well wrapped for
further use, for example by defining you own default theme.
I noted your PrimaryColor which made the example less self-consistant.
Check RColorBrewer and latticeExtra for a more standardize approach.
Dieter
"DMlatticeOptions" <- function(superpose.polygon.col=NULL,
superpose.line.col=NULL) {
require(lattice)
require(RColorBrewer)
ltheme = canonical.theme(color=TRUE)
if (!is.null(superpose.polygon.col))
ltheme$superpose.line$col = superpose.line.col else
ltheme$superpose.line$col =
c('black',"red","blue","#e31111","darkgreen", "gray")
# ltheme$superpose.line$col = rev(brewer.pal(8,"Set1"))
ltheme$superpose.fill$col = ltheme$superpose.line$col
if (!is.null(superpose.polygon.col))
ltheme$superpose.polygon$col = superpose.polygon.col
ltheme$strip.shingle$col = ltheme$superpose.polygon$col
ltheme$superpose.symbol$pch = c(16,17,18,1,2,3,4,8)
ltheme$superpose.symbol$col = ltheme$superpose.line$col
ltheme$superpose.symbol$cex = 0.4
ltheme$strip.background$col = c("gray90", "gray80")
ltheme$background$col = "transparent"
ltheme$par.main.text$cex = 0.9 # default is 1.2
ltheme$par.ylab.text$cex =0.8
ltheme$par.ylab.text$cex =0.8
ltheme$add.text$cex = 1
ltheme$axis.text$cex = 0.6
ltheme$box.rectangle$col = "black"
ltheme$box.umbrella$col = "black"
ltheme$dot.symbol$col = "black"
ltheme$plot.symbol$col = "black"
ltheme$plot.line$col = "black"
ltheme$plot.symbol$cex = 0.3
ltheme$plot.symbol$pch = c(16)
ltheme$plot.polygon$col = "#A6D96A"
ltheme$par.sub.text$cex=0.7
ltheme$par.sub.text$font=1
lattice.options(default.theme=ltheme)
}
More information about the R-help
mailing list