除了xlab3 x 3 条形图面板之外,我还想包含刻度线。我为单个图形尝试了这个解决方案,但不知何故我无法复制它。这个想法是用从 -3 到 +3 的 d 标记每个条形,并增加一个单位。每个图中的第一个条形表示 -3 的值。我试图用下面的模拟数据来证明我的问题。有任何想法吗?
# Data generation
# Populating a matrix
matrix(rnorm(63, 1:9), nrow=7, byrow=TRUE)
# Labelling the matrix
colnames(mat.s) <- c("Hs", "Sex", "Es", "Bo", "R", "W", "S", "Pri", "Abo")
# Tick mark indicator
d <- seq(-3,3,1)
# Plotting estimates
par(mfrow=c(3,3), mar = c(4,3,3,1))
for(i in 1:9) {
# Bar plot
barplot(mat.s[,i],
# X-label
xlab = colnames(mat.s)[i])
}
Run Code Online (Sandbox Code Playgroud)
在循环中的函数内指定axis.lty,names.arg和你会没事的:mgpbarplot
#I haven't changed anything else before the for-loop
#only changes have taken place inside the barplot function below
for(i in 1:9) {
# Bar plot
barplot(mat.s[,i], xlab = colnames(mat.s)[i],
names.arg= as.character(-3:3), axis.lty=1, mgp=c(3,1,0.2))
}
Run Code Online (Sandbox Code Playgroud)
输出:
更详细一点:
names.arg 将添加标签axis.lty=1 将添加一个 x 轴mgp是一个长度为 3 的向量,它按顺序控制标题、标签和轴线的边距。我只需要将它的第三个元素更改为 0.2,以便轴看起来不错(检查?par)。| 归档时间: |
|
| 查看次数: |
822 次 |
| 最近记录: |