由R绘制的条形图(标记,对应标签)与每个条形图不对应?

时间:2017-12-04 17:00:49

标签: r

但是它们是相同的长度向量,我尝试过很多部分代码,只是不能让“城市名称”对应每个条形码? 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()

1 个答案:

答案 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.