您是否在寻找不仅仅是更改边距、文本大小等的东西?
通过删去单数和截断名称,可以稍微提高可读性。
set.seed(1)
words <- sapply(
sample(3:25, 50, replace=TRUE),
function(x) {
paste(sample(c(letters), x, replace=TRUE), collapse="")
}
)
strtrunc <- function(x, l, r="…") {
trunc <- nchar(x) > l
x[trunc] <- paste0(strtrim(x[trunc], l), r)
x
}
samp <- sample(1:50, 500, replace=TRUE)
samp.t <- round(1.2^table(samp))
samp.t[sample(1:50, 20)] <- 1
names(samp.t) <- words
dev.new(width=10, height=5)
par(mar=c(10, 4, 3, 0.5), mgp=c(0, 0.8, -0.5), cex=0.9)
b <- barplot(samp.t, xaxt="n", space=0.5, col=1)
axis(1, at=b, labels=names(samp.t), las=2, tick=FALSE, cex.axis=0.8)
mtext("All counts", line=1, cex=1.5)
#barplot with logarithmic y-axis, truncated names and no single-counts
samp.ts <- samp.t[samp.t != 1]
names(samp.ts) <- strtrunc(names(samp.ts), 15)
dev.new(width=10, height=5)
par(mar=c(10, 4, 3, 0.5), mgp=c(0, 0.8, -0.5), cex=0.9)
b <- barplot(samp.ts, xaxt="n", space=0.5, col=1, log="y")
axis(1, at=b, labels=names(samp.ts), las=2, tick=FALSE, cex.axis=1.2)
mtext("Counts > 1", line=1, cex=1.5)
具有超过 20 个左右命名类别的条形图通常效果不佳,您最好找到一种不同的方式来可视化您的数据。如果对您的数据有意义,直方图或密度图可能是一种选择。否则,将条形图分成更小的部分,也许是由明智的群体,可能是另一个。