我的代码:
#!/usr/bin/R
layout(matrix(c(1, 1, 2, 2, 3, 3, 4, 4, 5), ncol=1))
# main plots
par(mar=c(5,2,4,2))
fcm <-c(14.0,14.1,13.0,14.2,14.7,13.8,14.0)
gk <-c(12.1,12.5,12.2,12.0,11.5,12.0,11.4)
gg <-c(14.0,14.1,13.3,12.8,12.0,12.2,12.0)
data1 <- rbind(fcm,gk,gg)
colnames(data1) <- c(6,7,8,9,10,11,12)
fcm <-c(2.65,2.55,2.4,2.45,2.45,2.5,2.45)
gk <-c(2.45,2.55,2.4,2.3,2.2,2.35,2.1)
gg <-c(2.6,2.65,2.5,2.35,2.4,2.4,2.2)
data2 <- rbind(fcm,gk,gg)
colnames(data2) <- c(6,7,8,9,10,11,12)
fcm <-c(8.8,6.5,6.6,8.2,8.0,8.4,9.0)
gk <-c(12.7,11.0,11.1,10.5,10.7,10.0,9.5)
gg <-c(2.1,2.1,1.8,2.0,2.0,1.9,1.8)
data3 <- rbind(fcm,gk,gg)
colnames(data3) <- c(6,7,8,9,10,11,12)
fcm <-c(0.47,0.53,0.45,0.39,0.40,0.47,0.48)
gk <-c(0.45,0.51,0.34,0.40,0.42,0.42,0.44)
data4 <- rbind(fcm,gk)
colnames(data4) <- c(6,7,8,9,10,11,12)
barplot(as.matrix(data1),ylim=c(0,15),main="P wave",
xlab="number of clusters", ylab="traveltime rms(ms)",
col=c("red", "black", "green"), beside=TRUE)
barplot(as.matrix(data2),ylim=c(0,3),main="MT",
xlab="number of clusters", ylab="MT functions",
col=c("red", "black", "green"), beside=TRUE)
barplot(as.matrix(data3),ylim=c(0,13),main="XBI",
xlab="number of clusters", ylab="index value",
col=c("red", "black", "green"), beside=TRUE)
barplot(as.matrix(data4),ylim=c(0,0.6),main="NCE",
xlab="number of clusters", ylab="index value",
col=c("red", "black"), beside=TRUE)
par(mai=c(0,0,0,0))
plot.new()
legend(legend = c("fcm","gk","gg"), fill = c( "red", "black", "green"),
"center", horiz=TRUE)
这张图片将成为我论文的一部分,计划将其提交给期刊。我担心编辑会抱怨价值观不可见。如何改变这一点?我的目标是所有的条形图之间有明显的区别,当然,如果这是可能的。
答案 0 :(得分:5)
堆积你的阴谋正在不必要地压缩它们。造成大量浪费的白色空间。
为什么不转换为2x2表示?
基本上你需要改变的是:
layout(matrix(c(1, 2, 5, 3, 4, 5), ncol=2))
我使用par(mar=c(3.1,2.1,2.1,0.1))
获得此输出:
你可能会注意到我们给传说留下了太多空间;这可以通过修改heights
参数到layout
来修复;这是heights=c(.45,.45,.1)
的输出。请参阅?layout
。
答案 1 :(得分:2)
我更喜欢@MichaelChirico的回答,但如果你出于某种原因需要将它们堆叠在一列中,这是另一种选择。我添加了评论来解释原始代码的更改。基本上,我通过使用边距和布局矩阵创建了一些额外的垂直空间,并摆脱了不必要的x轴标题:
# Change layout matrix to allow more vertical space for bottom plot
# (since it is now the only one with an x-axis title)
layout(matrix(1:5, ncol=1), heights=c(rep(0.21,3), 0.26, 0.11))
# main plots
par(mar=c(2,2.5,3.5,2)) # Decrease top and bottom margins
fcm <-c(14.0,14.1,13.0,14.2,14.7,13.8,14.0)
gk <-c(12.1,12.5,12.2,12.0,11.5,12.0,11.4)
gg <-c(14.0,14.1,13.3,12.8,12.0,12.2,12.0)
data1 <- rbind(fcm,gk,gg)
colnames(data1) <- c(6,7,8,9,10,11,12)
fcm <-c(2.65,2.55,2.4,2.45,2.45,2.5,2.45)
gk <-c(2.45,2.55,2.4,2.3,2.2,2.35,2.1)
gg <-c(2.6,2.65,2.5,2.35,2.4,2.4,2.2)
data2 <- rbind(fcm,gk,gg)
colnames(data2) <- c(6,7,8,9,10,11,12)
fcm <-c(8.8,6.5,6.6,8.2,8.0,8.4,9.0)
gk <-c(12.7,11.0,11.1,10.5,10.7,10.0,9.5)
gg <-c(2.1,2.1,1.8,2.0,2.0,1.9,1.8)
data3 <- rbind(fcm,gk,gg)
colnames(data3) <- c(6,7,8,9,10,11,12)
fcm <-c(0.47,0.53,0.45,0.39,0.40,0.47,0.48)
gk <-c(0.45,0.51,0.34,0.40,0.42,0.42,0.44)
data4 <- rbind(fcm,gk)
colnames(data4) <- c(6,7,8,9,10,11,12)
# Remove x-axis title from first three plots
# Add las=1 to all plots, so y-axis labels will be rotated
barplot(as.matrix(data1),ylim=c(0,15),main="P wave",
ylab="traveltime rms(ms)", las=1,
col=c("red", "black", "green"), beside=TRUE)
barplot(as.matrix(data2),ylim=c(0,3),main="MT",
ylab="MT functions", las=1,
col=c("red", "black", "green"), beside=TRUE)
barplot(as.matrix(data3),ylim=c(0,13),main="XBI",
ylab="index value", las=1,
col=c("red", "black", "green"), beside=TRUE)
# Change bottom margin for last plot so x-axis title will be included
par(mar=c(4,2.5,3.5,2))
barplot(as.matrix(data4),ylim=c(0,0.6),main="NCE",
xlab="number of clusters", ylab="index value", las=1,
col=c("red", "black"), beside=TRUE)
par(mai=c(0,0,0,0))
plot.new()
legend(legend = c("fcm","gk","gg"), fill = c( "red", "black", "green"),
"center", horiz=TRUE)
答案 2 :(得分:0)
我无法发表评论,所以我决定将其添加为答案...
让我们试试las和cex参数:
barplot(as.matrix(data1),ylim=c(0,15),main="P wave",
xlab="number of clusters", ylab="traveltime rms(ms)",
col=c("red", "black", "green"), beside=TRUE, las=1, cex.axis=.9)
您还可以通过减少mar paratemer的第一和第三元素来扩大条形区域。