Skip to content
Prev 336696 / 398513 Next

Lattice Barchart

Pete Brecknock wrote
I put together the following solution but would be interested in any other
approaches people may have to share.

library(lattice) 
library(latticeExtra)

d0 <-
structure(c(-1000,-2000,-2500,-5000,1000,2000,3000,2000,200,600,1000,900),
.Dim = c(4L, 3L), 
      .Dimnames = list(c("1/1/2014", "2/1/2014", "3/1/2014", "4/1/2014"),
NULL)) 
mycols <- c("red","brown","orange") 

d1 <- data.frame("Dt"=row.names(d0), "Sum"=rowSums(d0))

barchart(d0, 
         horizontal=FALSE, 
         stack=TRUE, 
         auto.key=list(text=c("A","B","C"), 
           columns =3, 
           title="", 
           cex.title =0.9, 
           border=FALSE), 
         xlab="Month", 
         ylab="Difference", 
         main="Stacked Barchart",
         par.settings = simpleTheme(col = mycols)) +

as.layer(xyplot(Sum~Dt, data=d1, type="o", pch=19, cex=1.8, col="black",
lwd=3), y.same=TRUE)

Thanks 

Pete



--
View this message in context: http://r.789695.n4.nabble.com/Lattice-Barchart-tp4685387p4685400.html
Sent from the R help mailing list archive at Nabble.com.