23
votes

In barplot, is it possible to make the labels parallel to the bars?

Suppose we have the data frame called "data".

              Page   PV UniquePgv
1 /photos/upcoming 5295      2733
2                / 4821      2996
3          /search 1201       605
4       /my_photos  827       340
5   /photos/circle  732       482

I want to make a barplot of PV with the Page column as the label.

names <-data$Page
barplot(data$PV,main="Page Views", horiz=TRUE,names.arg=names)

Which Produces:

enter image description here

The name of each bar is vertical, while the bars are horizontal.

How can I make the labels display horizontally and parallel with the bars? If it is not possible, I am open to suggestions for other ways to plot this information.

2
Doesn't look like there is anything in there to change the way the labels are displayed. Do you have any suggestions on a different way to plot this information?CompChemist

2 Answers

33
votes

You can use the las graphics parameter. However, if you do that, the names will run off the end of the window, so you need to change the margins. For example:

par(mai=c(1,2,1,1))
barplot(data$PV,main="Page Views", horiz=TRUE,names.arg=names,las=1)

enter image description here

-1
votes

enter image description here

enter image description hereng

esal = c(res$V3)

ename = res$V2 barplot(esal, names.arg=ename, col=c(rainbow(length(esal))), xlab="Employee Name", ylab="Salary", main="Emp V/S Salary")