gpt4 book ai didi

r - 在 r 的条形图面板中插入刻度线以及 xlab

转载 作者:行者123 更新时间:2023-12-04 10:43:15 25 4
gpt4 key购买 nike

除了 xlab 之外,我还想包括刻度线在一个 3 x 3 的条形图面板中。我试过 this单个图形的解决方案,但不知何故我无法复制它。这个想法是用从 -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])

}

最佳答案

指定 axis.lty , names.argmgpbarplot在循环中运行,你会没事的:

#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))
}

输出:

enter image description here

更详细一点:
  • names.arg将添加标签
  • axis.lty=1将添加一个 x 轴
  • mgp是一个长度为 3 的向量,它按顺序控制标题、标签和轴线的边距。我只需要将它的第三个元素更改为 0.2,以便轴看起来不错(检查 ?par )。
  • 关于r - 在 r 的条形图面板中插入刻度线以及 xlab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34207507/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com