【问题标题】:Fill area under geom_bspline()?在 geom_bspline() 下填充区域?
【发布时间】:2019-10-07 01:05:20
【问题描述】:

我看到geom_area 是如何用于填充直线下方的区域的。如何填充由geom_bspline 创建的曲线下的区域?

library("tidyverse")
library("ggforce")

dftest <- tibble(
  x = c(1, 2, 3, 4, 5),
  y = c(10, 15, 30, 80, 5)
)

# Fill area under straight lines - OK
ggplot(dftest, aes(x = x, y = y)) +
  geom_point() +
  geom_line() +
  geom_area(alpha = 0.3)

# Fill area under curve ???
ggplot(dftest, aes(x = x, y = y)) +
  geom_point() +
  geom_bspline() 

【问题讨论】:

    标签: r ggplot2 ggforce


    【解决方案1】:

    您可以使用与区域几何配对的统计数据:

    ggplot(dftest, aes(x = x, y = y)) +
      geom_point() +
      stat_bspline(geom = "area", alpha = 0.3) 
    

    【讨论】:

    • 谢谢。你能帮我解释一下 stat_bspline 和 geom_bspline 之间的区别吗?
    • 是的,stats 是对数据执行的计算,而 geoms 是数据的显示方式。如果你打印geom_bspline函数,你可以看到它将GeomPath传递给层,所以geom_bspline函数只是stat_bspline(geom = "path")的一个方便的包装器。
    • 太棒了。谢谢!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-10
    • 2011-12-15
    • 2020-07-02
    • 2018-11-01
    • 2021-12-23
    • 2012-10-20
    相关资源
    最近更新 更多