簡體   English   中英

fun.y 和 stat_summary 在 ggplot 中停止工作

[英]fun.y and stat_summary stopped working in ggplot

我曾經一直運行此代碼以在我的條形圖頂部獲得“n”的總和。

現在我收到以下錯誤:

忽略未知參數:fun.y

沒有提供摘要 function,默認為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
  ) 

ggplot 不再“求和”數據並忽略 vjust

這是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
  ) 

reprex package (v0.3.0) 創建於 2020-04-14

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM