我正在尝试在 r 中制作分组条形图,但有些事情我无法弄清楚。这是我到目前为止所拥有的:
我想:
- 从 data.frame(.csv 文件,见下文)创建矩阵
- ablines 出现,但不在栏的前面
- 分组条形图的标签(11 月、12 月、1 月……-> 参见下面的数据)
- 绘图布局如下所示。(我基本上想要情节边框)
我使用了以下代码:
x<-matrix(nrow=3,ncol=7, data=c(200,227,196,210,279,319,220,126,111,230,196,123,240,106,94,250,154,233,260,226,218))
tiff("p_month_all.tiff", width=600, height=300)
par(mar=c(5,4,0.5,0.5))
a=c("November","December","January","February","March","April","May")
barplot(x, beside=TRUE, ylim=c(0,350),xlab="Month", axes=TRUE,axis.lty=1, ylab="Monthly Precipitation [mm]", col=c("darkblue","dodgerblue3","deepskyblue1"),panel.first= abline(h = c(50,100,150,200,250,300), col = "grey", lty = 2), xaxt="n", yaxt="n")
par(ps=12, cex =1, cex.main=2)
axis(2, c(0,350, c(50, 100, 150, 200, 250, 300)), las=1)
dev.off()
数据集(.csv 文件)如下所示:
Month Hornberg Strick Huetten
November 120 278 234
December 279 156 145
January 328 300 299
February 267 259 234
March 190 201 187
April 150 199 177
May 147 156 160