我有这样的数据:
df <- tibble(
x = 1:20,
y = c(4, 4, 2, 1, 8, 3, 4, 2, 8, 2, 2, 2, 2, 6, 1, 7, 8, 9, 9, 2)
)图上,看上去如下:
df %>%
ggplot(aes(x, y)) +
geom_area()

但这张图确实令人不快。我怎样才能把锯齿状的边缘平滑成这样的东西:

谢谢!
发布于 2016-11-30 16:03:18
扩展Axeman的注释:光滑可以由span参数控制。
示例1:
df %>%
ggplot(aes(x, y)) +
# original, delete if desired
geom_area(alpha = 1/2) +
stat_smooth(
geom = 'area', method = 'loess', span = 1/3,
alpha = 1/2, fill = "red") +
labs(title = "Smooth with `span = 1/3`")

示例2:
df %>%
ggplot(aes(x, y)) +
geom_area(alpha = 1/2) +
# original, delete if desired
stat_smooth(
geom = 'area', method = 'loess', span = 7/10,
alpha = 1/2, fill = "blue") +
labs(title = "Smooth with `span = 7/10`")

https://stackoverflow.com/questions/40133833
复制相似问题