首页 > 解决方案 > 圆形 lineend geom_smooth

问题描述

如何制作圆形线条geom_smooth?因为没有 lineend 参数,geom_smooth(lineend = "round")显然失败了。我也徒劳地尝试过:

update_geom_defaults("smooth", list(lineend = "round"))

因此,要么有一些我不知道的简单选项,要么 lineend 是硬编码的,因此需要提出一个geom_smooth我不知道该怎么做的自定义函数。

不要认为它需要 MRE,但是:

library(ggplot2)
dat = data.frame(x = 1:3, y = 2:4)
ggplot(dat, aes(x, y)) + geom_smooth(size = 4)  # increase size to discern lineends

标签: rggplot2

解决方案


这可以通过以下方式实现stat_smooth

library(ggplot2)

dat = data.frame(x = 1:3, y = 2:4)

ggplot(dat, aes(x, y)) + stat_smooth(size = 4, geom = "line", lineend = "round", color = "blue")


推荐阅读