但是它们是相同的长度向量,我尝试了代码的许多部分,只是不能让"城市名称"对应每个bar?PDF宽度的问题?还是我不应该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()
barplot()期望这些名称位于name.arg参数中,呼叫barplot。请参阅此处的示例。不知道为什么轴标签失败。
##默认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.