我一直试图缩小x轴中标签的大小,这样所有的值都会出现,但不知道为什么不能工作。此外,我尝试使用mtext只为所有三个图放置一个x轴标签,但它也不起作用。有人能帮忙吗?以下是名为benefitlossr的数据
Region ChangeNPV ChangeNPVadjusted ChangeHC Scenario
Carabooda 13.47257941 7.430879051 0.1 S1-2
Carabooda 13.47151427 7.530120412 0.055 S2-3
Carabooda 14.83684617 8.940968276 0.056 S3-4
Carabooda 15.37691395 9.617533157 0.056 S4-5
Neerabup 3.499426472 2.232675752 0.01 S1-2
Neerabup 3.499596203 2.23966378 0.01 S2-3
Neerabup 3.836086106 2.566649186 0.01 S3-4
Neerabup 3.995114558 2.725839325 0.02 S4-5
Nowergup 3.513500149 1.700543633 0.02 S1-2
Nowergup 3.513585809 1.710386802 0.01 S2-3
Nowergup 3.850266108 2.034689127 0.02 S3-4
Nowergup 4.009112768 2.194350586 0.02 S4-5这是我的密码
Caraboodaloss <- subset(Benefitlossr, Region=="Carabooda")
Neerabuploss <- subset(Benefitlossr, Region=="Neerabup")
Nowerguploss <- subset(Benefitlossr, Region=="Nowergup")
Caraboodaloss
tiff("barplot.tiff", width=130, height=50, units='mm', res=300)
par(mfrow=c(1,3))
par(mar=c(5, 4, 4, 0.2))
mxCarabooda <- t(as.matrix(Caraboodaloss[,2:3]))
Caraboodaloss$Label <- paste(Caraboodaloss$Scenario, Caraboodaloss$ChangeHC)
colnames(mxCarabooda) <- Caraboodaloss$Label
colours=c("gray63","gray87")
barplot(mxCarabooda, main='Carabooda', ylab='Profit loss ($m)',
xlab='Change in water table at each level of GW cut', beside=TRUE,
col=colours, ylim=c(0,30),cex.lab=0.7, cex.sub=0.7, cex.axis=0.7)
legend('topright', bty="n", legend=c('Loss in GM','Loss in adjusted GM'),
col=c("gray63","gray87"), cex=0.6, pch=15)
mxNeerabup <- t(as.matrix(Neerabuploss[,2:3]))
Neerabuploss$Label <- paste(Neerabuploss$Scenario, Caraboodaloss$ChangeHC)
colnames(mxNeerabup) <- Neerabuploss$Label
colours=c("gray63","gray87")
barplot(mxNeerabup,main='Neerabup', ylab='',
xlab='Change in water table at each level of GW cut', beside=TRUE,
col=colours, ylim=c(0,30), cex.lab=0.7, cex.sub=0.7, cex.axis=0.7)
legend('topright', bty="n", legend=c('Loss in GM','Loss in adjusted GM'),
col=c("gray63","gray87"), cex=0.6, pch=15)
mxNowergup <- t(as.matrix(Nowerguploss[,2:3]))
Nowerguploss$Label <- paste(Nowerguploss$Scenario,Nowerguploss$ChangeHC)
colnames(mxNowergup) <- Nowerguploss$Label
colours=c("gray63","gray87")
barplot(mxNowergup,main='Nowergup', ylab='',
xlab='Change in water table at each level of GW cut',beside=TRUE,
col=colours, ylim=c(0,30), cex.lab=0.7, cex.sub=0.7, cex.axis=0.7)
legend('topright', bty="n", legend=c('Loss in GM','Loss in adjusted GM'),
col=c("gray63","gray87"), cex=0.6, pch=15)
dev.off()这就是我得到的结果

X轴标签太大,即使y轴标签尺寸减少.因此,并不是所有的值都可以显示在轴上。如果可能的话,我希望在图中清楚地看到x轴的所有标签。我不能改变宽度和高度的大小,因为它是必需的。
发布于 2019-03-24 07:26:40
使用mtext获取全局轴标签是一个好主意。你也可以用传说做这件事。对于滴答标签,我建议把它们转90度。因此,总体可读性应该有所提高。(可能会比我提供的解决方案更好地调整。)
首先,我们将矩阵放入一个列表中,并使用barplot在lapply中保存类型。
L <- list(mxCarabooda=mxCarabooda, mxNeerabup=mxNeerabup, mxNowergup=mxNeerabup)在par选项中,我们包括oma以扩大外部边距,xpd将文本和图例放置在任何地方。在barplot中,我们关闭x轴并手动添加它们。通过设置lossless compression来使用compression="lzw"。
tiff("barplot.tiff", width=260, height=100, units='mm', res=300, compression="lzw")
par(mfrow=c(1,3), mar=c(5, 4, 4, 2) + 0.1, oma=c(6, 4, 0, 0), xpd=TRUE)
lapply(seq_along(L), function(x) {
b1 <- barplot(L[[x]], main=gsub("^mx", "", names(L)[x]), beside=TRUE, xaxt="n",
col=c("gray63","gray87"), ylim=c(0,30))
axis(1, at=apply(b1, 2, mean), labels=colnames(L[[x]]),
tick=FALSE, line=FALSE, las=2)
})
mtext('Change in water table at each level of GW cut', side=1, outer=TRUE, line=1) # x-lab
mtext('Profit loss ($m)', side=2, outer=TRUE, line=1) # y-lab
legend(-16.5, -15, bty="n", legend=c('Loss in GM','Loss in adjusted GM'),
col=c("gray63","gray87"), cex=1.2, pch=15, horiz=TRUE, xpd=NA)
dev.off()结果

然而,要使解决方案有效,我必须至少翻倍于tiff大小,因为数字边距太大了。然而,纵横比保持不变,这一点应该更重要。你能用你的日记查一下吗?也许您也可以使用pdf("barplot.pdf", width=13, height=5)而不是tiff(.)行。
数据
mxCarabooda <- structure(c(13.47258, 7.430879, 13.47151, 7.53012, 14.83685,
8.940968, 15.37691, 9.617533), .Dim = c(2L, 4L), .Dimnames = list(
c("ChangeNP", "ChangeNP.1"), c("Sl-2 0.1", "S2-3 0.055",
"S3-4 0.056", "S4-5 0.056")))
mxNeerabup <- structure(c(3.499426, 2.232676, 3.499596, 2.239664, 3.836086,
2.566649, 3.995115, 2.725839), .Dim = c(2L, 4L), .Dimnames = list(
c("ChangeNP", "ChangeNP.1"), c("Sl-2 0.1", "S2-3 0.055",
"S3-4 0.056", "S4-5 0.056")))
mxNowergup <- structure(c(3.5135, 1.700544, 3.513586, 1.710387, 3.850266, 2.034689,
4.009113, 2.194351), .Dim = c(2L, 4L), .Dimnames = list(
c("ChangeNP", "ChangeNP.1"), c("Sl-2 0.02", "S2-3 0.01",
"S3-4 0.02", "S4-5 0.02")))发布于 2019-03-24 15:39:26
您还可以在初始的par调用中单独设置参数,而不是在每个标题栏中单独设置参数,还可以设置las=2以获得滴答标签的垂直方向。
tiff("barplot.tiff", width=130, height=50, units='mm', res=300)
par(mfrow=c(1,3))
par(mar=c(5, 4, 4, 0.2), cex.lab=0.5, cex.sub=0.7, cex.axis=0.5, las=2)
mxCarabooda <- t(as.matrix(Caraboodaloss[,2:3]))
Caraboodaloss$Label <- paste(Caraboodaloss$Scenario, Caraboodaloss$ChangeHC)
colnames(mxCarabooda) <- Caraboodaloss$Label
colours=c("gray63","gray87")
barplot(mxCarabooda, main='Carabooda', ylab='Profit loss ($m)',
xlab='Change in water table at each level of GW cut', beside=TRUE,
col=colours, ylim=c(0,30))
legend('topright', bty="n", legend=c('Loss in GM','Loss in adjusted GM'),
col=c("gray63","gray87"), cex=0.6, pch=15)
mxNeerabup <- t(as.matrix(Neerabuploss[,2:3]))
Neerabuploss$Label <- paste(Neerabuploss$Scenario, Caraboodaloss$ChangeHC)
colnames(mxNeerabup) <- Neerabuploss$Label
colours=c("gray63","gray87")
barplot(mxNeerabup,main='Neerabup', ylab='',
xlab='Change in water table at each level of GW cut', beside=TRUE,
col=colours, ylim=c(0,30) )
legend('topright', bty="n", legend=c('Loss in GM','Loss in adjusted GM'),
col=c("gray63","gray87"), cex=0.6, pch=15)
mxNowergup <- t(as.matrix(Nowerguploss[,2:3]))
Nowerguploss$Label <- paste(Nowerguploss$Scenario,Nowerguploss$ChangeHC)
colnames(mxNowergup) <- Nowerguploss$Label
colours=c("gray63","gray87")
barplot(mxNowergup,main='Nowergup', ylab='',
xlab='Change in water table at each level of GW cut',beside=TRUE,
col=colours, ylim=c(0,30) )
legend('topright', bty="n", legend=c('Loss in GM','Loss in adjusted GM'),
col=c("gray63","gray87"), cex=0.6, pch=15)
dev.off()

https://stackoverflow.com/questions/55321067
复制相似问题