【问题标题】:Annotate ggplot bar plot in R在R中注释ggplot条形图
【发布时间】:2022-06-21 23:54:55
【问题描述】:

如何注释以下情节?我想在每个栏的顶部包含计数。

g <- ggplot(mpg, aes(class))
# Number of cars in each class:
g + geom_bar()

例如,如果我进行分组并创建一个新列“计数”,我只知道该怎么做。

【问题讨论】:

    标签: r ggplot2 dplyr


    【解决方案1】:

    你可以这样做:

    ggplot(mpg, aes(class)) + 
      geom_bar() +
      geom_text(stat = "count", aes(label = after_stat(count)), nudge_y = 1)
    

    【讨论】:

    • 谢谢!我怎样才能把标签放高一点?
    猜你喜欢
    • 2013-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多