On Dec 2, 2009, at 6:27 PM, Peng Cai wrote:

Hi R Users,

I'm using following data/code (data is also attached) to produce a stacked
barplot.

*I need help with changing legend boxes, currently I'm using
"rectangles=TRUE". Is it possible to get small squares instead -- may be with a small gap between colored squares.* Currently there is no gap between
the colored rectangles.

# Sample Data:
Names Col1 Col2 Col3
Row1 -20 40 -10
Row2 30 -20 40
Row3 30 10 -20
Row4 20 20 -10


# R Code:
dta<-read.table("data.txt", header=TRUE, row.names="Names")
barchart(data.matrix(dta),
     horizontal=FALSE,
     stack=TRUE,
     par.settings = simpleTheme(col = 3:5),
     auto.key=list(space="right", rectangles=TRUE, points = FALSE),
     border=NA,
   scales = list(relation="free", y = list(at = yScale)),
   panel=function(x,y,...)
   {
       panel.abline(h=c(yScale), col.line="gray")
           panel.barchart(x,y,...)
   }
)

I think you need to go to a key argument:
library(lattice)
yScale <- seq(-200, 200, 10)
barchart(data.matrix(dta),
     horizontal=FALSE,
     stack=TRUE,
     par.settings = simpleTheme(col = 3:5),
key=list(space="right", text=list(colnames(dta)), rectangles=list(size=2, border="white", col=3:5) ),
     border=NA,
   scales = list(relation="free", y = list(at = yScale)),
   panel=function(x,y,...)
   {
       panel.abline(h=c(yScale), col.line="gray")
           panel.barchart(x,y,...)
   }
)

--
David.

Any help would be appreciated,

Thanks,
Peng
<data.txt>______________________________________________
R-help@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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

______________________________________________
R-help@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.

Reply via email to