【问题标题】:Selectively make one section of axis line thicker in ggplot在ggplot中选择性地使一部分轴线变粗
【发布时间】:2017-10-12 08:21:30
【问题描述】:

我想使用 ggplot2 绘制密度图,并使 x 轴线的一部分更粗(或颜色不同)。

例如:

interval <- c(x1,x2)
x <- ggplot(df, aes(x=value)) + geom_density()

有没有办法选择性地使对应于 (x1,x2) 的 x 轴段变粗或着色不同?谢谢。

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    您可以使用annotate 添加线段。将 y 坐标设置为 -Inf 会将其放置在 x 轴上。由于您的示例不可重现,因此我已在 mtcars 数据上进行了演示:

    ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() +
      annotate(
        geom = "segment",
        x = 3, xend = 4,
        y = -Inf, yend = -Inf,
        color = "blue",
        size = 5
      )
    

    【讨论】:

    • 非常感谢!这正是我想做的。
    猜你喜欢
    • 2023-01-30
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-28
    • 2019-10-09
    • 1970-01-01
    • 2018-02-09
    • 2016-03-15
    相关资源
    最近更新 更多