R: How can I make a barplot with labels parallel (horizontal) to bars

[亡魂溺海] 提交于 2019-12-31 18:01:52

问题


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:

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.


回答1:


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)




回答2:


ng

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")



来源:https://stackoverflow.com/questions/19437934/r-how-can-i-make-a-barplot-with-labels-parallel-horizontal-to-bars

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!