r - fun.y 和 stat_summary 停止在 ggplot 中工作
问题描述
我曾经一直运行此代码以在我的条形图顶部获得“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
)
解决方案
这是ggplot2
release的 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
)
由reprex 包(v0.3.0)于 2020-04-14 创建
推荐阅读
- c# - 将 SQL 查询转换为 linq lambda Entity Framework Core
- postgresql - 聚合函数作为元组参数 postgres
- python - 你如何比较字典和列表
- websphere - 如何在项目的资产类型中添加笔记本?
- javascript - 有没有办法使用 javascript 将样式应用于突出显示的文本?
- google-apps-script - 如何从谷歌脚本向 BigQuery 发出正确的 HTTP 请求
- java - Spring Boot 2.x Servlet Path 在测试中被忽略
- php - 在 Lumen 7 中验证时如何返回自定义 JSON 数组名称和内部元素?
- python - 如何检查是否在tkinter的文本字段中单击了左键?
- mongodb - Docker:等待 Mongodb ReplicaSet