2
我正在使用layout()在R中創建多個陰謀圖並且只想要y軸顯示在底部陰謀圖中。因此,我把它們從循環中移出,並將它們添加到軸的下面,但是當我這樣做時,它們會被切斷。這裏是我正在使用的代碼:軸在R中的多個陰謀圖中切斷
onlytext <- function(string){
plot(0:1, 0:1, bty='n', type='n', xaxt='n', yaxt='n', xlab='', ylab='')
text(0.5, 0.5, string, cex=1.2, font=2)
}
nf <- layout(matrix(c(0,1:14), 5, 3, byrow=TRUE), heights = c(2,5,5,5,5), widths = c(1.5,4,4))
par (mar=c(.3,.3,.3,.3))
onlytext ('Approval'); onlytext ('Vote Choice')
name_vec <- c("Strongly Approve", "Approve", "Disapprove", "Strongly Disapprove")
control_means_tab <- matrix(sample(rnorm(100), 48), ncol = 6, nrow = 4)
x <- seq(1,6)
for(i in 1:3){
onlytext(name_vec[i])
for(j in 1:2){
plot(x, control_means_tab[j,], xaxt = 'n', xlab = '', ylab = '', xaxt='n', bty = "n", ylim = c((min(c(control_means_tab, scorecard_means_tab, endorsement_means_tab))- .02),(max(c(control_means_tab, scorecard_means_tab, endorsement_means_tab)) + .02)), col = "blue", pch = 19, cex =.6)
}
}
onlytext(name_vec[4])
plot(x, control_means_tab[j,], xlab = '', ylab = '', xaxt = "n", bty = "n", ylim = c((min(c(control_means_tab, scorecard_means_tab, endorsement_means_tab))- .02),(max(c(control_means_tab, scorecard_means_tab, endorsement_means_tab)) + .02)), col = "blue", pch = 19, cex =.6)
axis(1, 1:6, LETTERS[1:6])
plot(x, control_means_tab[j,], xaxt = 'n', xlab = '', ylab = '', xaxt='n', bty = "n", ylim = c((min(c(control_means_tab, scorecard_means_tab, endorsement_means_tab))- .02),(max(c(control_means_tab, scorecard_means_tab, endorsement_means_tab)) + .02)), col = "blue", pch = 19, cex =.6)
axis(1, 1:6, LETTERS[1:6])
有關如何獲得該軸的任何想法是讚賞!
您的代碼不會爲我運行。此外,我不明白爲什麼佈局()矩陣有14個地塊的空間(0表示沒有繪製在該位置),但有8個地塊(循環中6個,外部2個)。 – rbatt