axis(1, c(1:47)
?试过但不解决......提醒也会心存感激。
pdf("barplot1.pdf", width = 8.6, height = 8)
matrix_tem <- t(matrix(each_bar_number)) #each_bar_number is a vector, length(each_bar_number) is 47
barplot(matrix_tem, ylim = c(0, 150), xaxt="n", border=NA, space = NULL, beside=F)
axis(1, c(1:47), labels=as.character(cityname_vector), las = 2,cex.axis = 0.6) #length(cityname_vector) is 47
dev.off()
答案 0 :(得分:1)
barplot()要求名称在barplot调用中的names.arg参数中。有关示例,请参阅here。不确定为什么轴标签失败。
##默认S3方法:
barplot(height, width = 1, space = NULL,
names.arg = NULL, legend.text = NULL, beside = FALSE,
horiz = FALSE, density = NULL, angle = 45,
col = NULL, border = par("fg"),
main = NULL, sub = NULL, xlab = NULL, ylab = NULL,
xlim = NULL, ylim = NULL, xpd = TRUE, log = "",
axes = TRUE, axisnames = TRUE,
cex.axis = par("cex.axis"), cex.names = par("cex.axis"),
inside = TRUE, plot = TRUE, axis.lty = 0, offset = 0,
add = FALSE, args.legend = NULL, ...)
<强>参数强>
names.arg
a vector of names to be plotted below each bar or group of bars.
If this argument is omitted, then the names are taken from the
names attribute of height if this is a vector, or the column
names if it is a matrix.