我想用两个不同的y轴创建垂直条形图。这是我尝试使用lattice和latticeExtra:
mydata <- data.frame(
methods = c(1,2,3,4,5,6,7,8,9,10),
aMW = c(9.29,9.88,1.38,9.06,4.71,4.89,0.73,4.67,10.09,10.56),
aMW_perSF = c(0.77,0.82,0.35,0.98,0.86,0.90,0.69,0.93,0.72,0.75)
)
attach(mydata)
library(lattice)
library(latticeExtra)
png("test2.png", width=800, height=600)
h1a = barchart( aMW_perSF ~ methods, data=mydata, horizontal=FALSE, stack = FALSE,
main="Electricity aMW Saved",
ylab = list(label=expression("electricity savings intensity " (aMW/ft^2)), fontsize=14), ylim=c(0,1.5),
scales=list(y=list(labels=c("","","","","","","","","","","","","",""),tick.number=10))
)
h1b = barchart( aMW ~ methods, data=mydata, horizontal=FALSE, stack = FALSE,
main="Electricity aMW Saved",
ylab = "electricity savings", ylim=c(0,15),
scales=list(y=list(labels=c("","","","","","","","","","","","","",""),tick.number=10))
)
doubleYScale(obj1 = h1a, obj2 = h1b, add.ylab2 = TRUE,
text = c("aMW","aMW/ft2")
)
结果如下。如你所见: