gpt4 book ai didi

r - 计算 ggplot 3.3.0 中 `scale_x_binned` 直方图的标签

转载 作者:行者123 更新时间:2023-12-04 10:03:32 29 4
gpt4 key购买 nike

在版本 3.3.0 of ggplot2 ,我们现在有了 scale_*_binned装箱秤。这在创建更具视觉吸引力的直方图时很有用

  • 如何在指示计数的直方图条上添加标签?

  • 我在 + geom_text(aes(label = ...)) 的标签参数中放了什么

    我觉得答案就在 ggplot 对象中保存的对象中的某个地方 p (见下文)以某处计算量的形式,但我似乎无法找到它。


    library(ggplot2)
    #> Warning: package 'ggplot2' was built under R version 3.6.3

    p <-
    ggplot(mtcars) +
    geom_bar(aes(mpg)) +
    scale_x_binned()

    p




    names(p)
    #> [1] "data" "layers" "scales" "mapping" "theme"
    #> [6] "coordinates" "facet" "plot_env" "labels"

    创建于 2020-05-10 由 reprex package (v0.3.0)

    最佳答案

    计数的标签可以通过 geom_text(aes(x = mpg, label = ..count..), stat = "count") 添加.尝试这个

    library(ggplot2)

    p <-
    ggplot(mtcars) +
    geom_bar(aes(mpg)) +
    geom_text(aes(x = mpg, label = ..count..), stat = "count", vjust = -.2) +
    scale_x_binned()

    p



    创建于 2020-05-10 由 reprex package (v0.3.0)

    关于r - 计算 ggplot 3.3.0 中 `scale_x_binned` 直方图的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61708996/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com