Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

names on the x-axis of barplot in R?

Tags:

r

bar-chart

I am plotting barplot in r.

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.

How can I label those missing labels?

like image 209
Issac Avatar asked Jan 08 '23 22:01

Issac


1 Answers

You can try making the labels smaller with 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
like image 81
C_Z_ Avatar answered Jan 23 '23 04:01

C_Z_