R:如何制作标签与条形平行(水平)的条形图

问题描述 投票:0回答:2

在条形图中,是否可以使标签与条形平行?

假设我们有一个名为“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

我想制作一个PV的条形图,以Page列作为标签。

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

产生:

enter image description here

每个栏的名称是垂直的,而栏是水平的。

如何使标签水平显示并与条形平行?如果不可能,我愿意接受有关绘制此信息的其他方法的建议。

r label bar-chart
2个回答
36
投票

您可以使用

las
图形参数。但是,如果这样做,名称将超出窗口末尾,因此您需要更改边距。例如:

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
投票

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")
© www.soinside.com 2019 - 2024. All rights reserved.