如何在y轴上构建具有比例值的直方图?

时间:2014-09-02 15:22:46

标签: r charts histogram frequency axis-labels

我正在用 R 语言试验 ggplot 包。 我的任务是绘制这篇优秀论文中图片中显示的图表: http://cmup.fc.up.pt/cmup/engmat/2012/seminario/artigos2012/Luis_Ferreira/Using%20logistic%20regression%20to%20estimate%20the%20influence%20of%20accident.pdf

你能否告诉我如何策划这个? 提前谢谢

Example of the plot I need to build in R language

2 个答案:

答案 0 :(得分:1)

我认为这就是你要找的东西:

# Category names
my.names <- c("test1","test2","test3")

# Example data
data <- runif(length(my.names))

# Normalize the example data as a percentage of the total
data.norm <- data / sum(data)

# Use barplot to plot the results, plot without an x axis
x <- barplot(data.norm,names.arg=my.names,xaxt="n")

# Apply new x labels rotated by 45 degrees
text(cex=1, x=x-0.1, y=-0.05, my.names, xpd=TRUE, srt=45)

答案 1 :(得分:0)

这就是我的所作所为:

bp<-barplot(data.norm, beside=TRUE, col=c("grey10","grey20","grey30","grey40","grey50","grey60","grey70","grey80","grey90","grey80","grey70","grey60",))text(bp, par("usr")[3], labels=my.names, srt=45, pos=2, xpd=TRUE,offset=0.01)

这对我的目的来说很好。希望这对其他人有帮助 此致