我过去常常运行这段代码来获取条形图顶部“n”的总和。
现在我收到以下错误:
忽略未知参数:fun.y
没有提供汇总函数,默认为
mean_se()
count %>%
ggplot(aes(x = date, y = n, group = class, fill = class)) +
geom_col() +
geom_text_repel(
aes(label = stat(y), group = date),
stat = 'summary', fun.y = sum, vjust = -1
)
Run Code Online (Sandbox Code Playgroud)
ggplot2这是与 一起发布的 API 的变化ggplot2 3.3.0。来自文档:
fun.ymin、fun.y、fun.ymax 已弃用,请改用上面指定的版本。
只需切换到fun.
library(ggrepel)
library(ggplot2)
library(dplyr)
mtcars %>%
count(gear, cyl) %>%
ggplot(aes(x = factor(gear), y = n, group = factor(cyl), fill = factor(cyl))) +
geom_col() +
geom_text_repel(
aes(label = stat(y), group = factor(gear)),
stat = 'summary', fun = sum, vjust = -1
)
Run Code Online (Sandbox Code Playgroud)

由reprex 包(v0.3.0)于 2020-04-14 创建