【问题标题】:How can I build histogram with proportion values in y-axis?如何在 y 轴上构建具有比例值的直方图?
【发布时间】:2023-03-24 00:41:01
【问题描述】:

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

你能给我一些关于如何绘制这个的提示吗? 提前谢谢你

【问题讨论】:

    标签: r charts histogram frequency axis-labels


    【解决方案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)
    

    【讨论】:

    • 您能告诉我如何修改代码以使 x 轴上的标签旋转 45 度吗?问候
    • 我在上面编辑了我的回复,将标签旋转了 45 度。希望对您有所帮助。
    【解决方案2】:

    这就是我的工作:

    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)
    

    对于我的目的来说它工作得很好。希望这对其他人有帮助 问候

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-13
      • 2012-08-18
      • 1970-01-01
      • 2020-12-26
      • 2021-03-03
      • 1970-01-01
      • 2019-07-08
      • 2012-05-17
      相关资源
      最近更新 更多