user2543622
user2543622

Reputation: 6766

How to display long x axis labels in R

I have data and chart as below. My x axis labels are really long and I cannot trim them. When i plot the graph, those labels get trimmed. How could i keep actual graph area same while showing the entire labels? Those labels should be readable and i dont want to reduce their font and I also dont want to change scale of my y axis

x=c(20,30,70,5)
y=c("afsdfsdffffffffasdfsadfsadfd","adfsfsdafdsafdaffads","fdasfafddafaf","fadfsafsdfdfa")
bb=barplot(x,space=10, ylab="Average fare $", ylim=c(0,70))
grid(lty=8,col="black")
axis(1,at=bb,labels=y,las=2)

update 1

I tried below command before plot. But the first command doesnt work at all and the second command reduces my actual plot area :(

would it be possible to increase height of the entire chart (x axis labels + actual graph)?

x11(width=5, height=30)
par(mar=c(11,4,2,2)+0.1)

Upvotes: 0

Views: 1921

Answers (1)

Remo
Remo

Reputation: 53

You could just define your own plotting parameters, before you plot the chart. Use for example these parameters at the start of your code.

par(mar = c(13, 4, 4, 2) + 0.1) # set bottom margin to a higher value

Also don't forget to reset them to the default values after the plot. Which are: mar = c(5, 4, 4, 2) + 0.1

Source: https://www.statmethods.net/advgraphs/parameters.html

Upvotes: 1

Related Questions