带有两个y轴的垂直条形图

时间:2012-04-30 21:07:03

标签: r lattice

我想用两个不同的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")
              )

结果如下。如你所见:

  1. 两个酒吧在彼此的顶部。如何为两组柱子创建偏移量?
  2. 其中一个y轴标签不正确,可能是因为超级标签(ft2)产生错误。如何解决这个问题?
  3. 钥匙印在顶部。如何把它放在右上角的图表中?此外,钥匙被指示为一条线,如何将它们作为盒子? enter image description here

0 个答案:

没有答案