Hello! 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.? Thanks a lot! -- Dimitri Liakhovitski MarketTools, Inc. Dimitri.Liakhovitski at markettools.com
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) }
Thanks a lot, Sundar. I experimented somewhat and here is the code that works well - it allows me to modify most of the stuff I want to modify: p<-as.vector(c(0.1, 0.2, 0.3, 0.4)) names(p)<-c("AAAAA","BBBBBB","CCCCCCCCCCCC","DDDDDDDD") barchart(~sort(p), main=list("Chart Title",cex=1),xlab=list("X axis title",cex=1),xlim=c(0,0.42), layout = c(1,1), stack = TRUE, auto.key = list(points = FALSE, rectangles = TRUE, space = "top"), panel = function(y,x,...){ panel.grid(h = 0, v = -1, col = "gray60", lty ="dotted") panel.barchart(x,y,col="brown") panel.text(x,y,label = round(x,2),cex=1) } ) One last question: How can I modify the way the value labels (those that are at the end of the bars) appear? Can I make them bold? Make them appear a bit to the right or to the left of where they currently are? Thanks a lot! Dimitri On Wed, Feb 11, 2009 at 12:46 PM, Sundar Dorai-Raj <sdorairaj at gmail.com> wrote:> Pass a list to xlab and main for the font sizes: > > barchart(..., xlab = list("x-axis", cex = 2), main = list("title", cex = 2)) > > For value labels and a grid you'll need a custom panel function: > > barchart(..., panel = function(x, y, ...) { > panel.barchart(x, y, ...) > panel.text(x, y, format(y), cex = 1.2) > panel.grid(h = -1, v = -1) > }) > > This is untested, but I think it should get you started. > > --sundar > > On Wed, Feb 11, 2009 at 9:10 AM, Dimitri Liakhovitski <ld7631 at gmail.com> wrote: >> Hello! >> >> 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.? >> >> Thanks a lot! >> >> -- >> Dimitri Liakhovitski >> MarketTools, Inc. >> Dimitri.Liakhovitski at markettools.com >> >> ______________________________________________ >> 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. >> >-- Dimitri Liakhovitski MarketTools, Inc. Dimitri.Liakhovitski at markettools.com
Reasonably Related Threads
- Barchart in lattice - wrong order of groups, data labels on top of each other, and a legend question
- Printing out a graph using different graphics devices
- Question about multiple regression
- rbind data frames stored in a list
- Increasing the font size on axes in trellis