简体   繁体   English

R中条形图的x轴上的名字?

[英]names on the x-axis of barplot in R?

I am plotting barplot in r. 我正在策划r中的barplot。

my data: 我的数据:

   ,Up,Down
Floor-1,690,1511
Maxim,1354,2515
Hosiptal,1358,2649
Bank,459,589
Air-port,1359,2097
Bus-stand,1234,1928
Taxi-Stand,213,138
Railway-station,557,610

The barplot of the script is at: Link to image 脚本的条形图位于: 链接到图像

As I don't have enough reputation; 因为我没有足够的声誉; I can't post the image ... :) 我无法发布图片...... :)

my script is : 我的脚本是:

  d <- read.csv("file.csv")
  barplot(t(as.matrix(d[, 2:3])),beside=TRUE,legend = c("Up","Down"),  ylab = "Number of steps",
    xlab = "Building", main = "Up and Down steps",names.arg= as.matrix(d$X) ,col=rainbow(2),type="h")

In this plot the lables of x-axis "Bus-stand" and and "Railway-station" are missing. 在该图中,缺少x轴“公交车站”和“火车站”的标签。

How can I label those missing labels? 如何标记丢失的标签?

You can try making the labels smaller with cex.names 您可以尝试使用cex.names缩小标签

x<- c(10, 20, 30, 40, 50)

names <- c("Name", "Long name", "This name is long", "Name", "Name")

barplot(x, names.arg=names)
# Names might not all fit, depending on size of graph
barplot(x, names.arg=names, cex.names=.5)
# All names will probably fit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM