R语言ggblanket美化ggplot的图

KJY / 2022-05-15


R语言ggblanket美化ggplot图

参考:

https://davidhodge931.github.io/ggblanket/

# install.packages("ggblanket")
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
library(ggblanket)
penguins2 <- palmerpenguins::penguins %>% 
  tidyr::drop_na() %>% 
  mutate(body_mass_kg = body_mass_g / 1000) 

sample_n(penguins2, 10)
## # A tibble: 10 x 9
##    species   island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
##    <fct>     <fct>           <dbl>         <dbl>             <int>       <int>
##  1 Adelie    Biscoe           35.9          19.2               189        3800
##  2 Chinstrap Dream            43.2          16.6               187        2900
##  3 Adelie    Dream            40.2          20.1               200        3975
##  4 Chinstrap Dream            50.5          19.6               201        4050
##  5 Gentoo    Biscoe           50            15.9               224        5350
##  6 Chinstrap Dream            51.9          19.5               206        3950
##  7 Gentoo    Biscoe           47.7          15                 216        4750
##  8 Gentoo    Biscoe           48.4          14.4               203        4625
##  9 Chinstrap Dream            48.5          17.5               191        3400
## 10 Adelie    Dream            36            17.8               195        3450
## # … with 3 more variables: sex <fct>, year <int>, body_mass_kg <dbl>

这是默认的gg histogram

penguins2 %>% 
  ggplot() +
  geom_histogram(aes(x = body_mass_kg)) 
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

使用这个包的话就步骤更简单,然后更好看

penguins2 %>% 
  gg_histogram(x = body_mass_kg)
## Scale for 'x' is already present. Adding another scale for 'x', which will
## replace the existing scale.
## Warning: Removed 2 rows containing missing values (geom_bar).

这是默认的图

penguins2 %>%
  group_by(species, sex, island) %>%
  summarise(body_mass_kg = mean(body_mass_kg)) %>%
  ggplot() +
  geom_col(
    aes(x = body_mass_kg, y = species, fill = sex), 
    position = "dodge"
    ) +
  facet_wrap( ~ island) +
  theme(legend.position = "bottom")
## `summarise()` has grouped output by 'species', 'sex'. You can override using the `.groups` argument.

可以看得到就代码更加简单了

penguins2 %>%
  group_by(species, sex, island) %>%
  summarise(body_mass_kg = mean(body_mass_kg)) %>%
  gg_col(
    x = body_mass_kg,
    y = species,
    col = sex,
    facet = island,
    position = "dodge",
    col_legend_place = "b"
  )
## `summarise()` has grouped output by 'species', 'sex'. You can override using the `.groups` argument.
## {ggblanket} merges col and fill aesthetics into a single col aesthetic
## {ggblanket} treats faceting as an aesthetic
## Warning: Ignoring unknown parameters: stat

storms %>% 
  group_by(year) %>% 
  summarise(wind = mean(wind, na.rm = TRUE)) %>% 
  gg_line(x = year, 
          y = wind, 
          y_zero = TRUE,
          title = "Storm wind speed",
          subtitle = "USA average storm wind speed, 1975\u20132020", 
          y_title = "Wind speed (knots)", 
          caption = "Source: NOAA",
          theme = gg_theme(y_grid = TRUE)) +
  geom_point()

penguins2 %>% 
  gg_density(
    x = body_mass_kg, 
    col = species, 
    facet = sex, 
    col_legend_place = "b")
## {ggblanket} merges col and fill aesthetics into a single col aesthetic
## {ggblanket} treats faceting as an aesthetic
## Scale for 'x' is already present. Adding another scale for 'x', which will
## replace the existing scale.

penguins2 %>% 
  gg_smooth(
    x = bill_length_mm,
    y = flipper_length_mm,
    col = species,
    ) 
## {ggblanket} merges col and fill aesthetics into a single col aesthetic
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

这里有个包:‘pals’

https://cran.r-project.org/web/packages/pals/vignettes/pals_examples.html

penguins2 %>%
  gg_histogram(
    x = body_mass_kg,
    col = species, 
    facet = sex, 
    col_legend_place = "b", 
    pal = pals::brewer.dark2(3))
## {ggblanket} merges col and fill aesthetics into a single col aesthetic
## {ggblanket} treats faceting as an aesthetic
## Scale for 'x' is already present. Adding another scale for 'x', which will
## replace the existing scale.
## Warning: Removed 12 rows containing missing values (geom_bar).

df <- data.frame(
  trt = factor(c(1, 1, 2, 2)),
  resp = c(1, 5, 3, 4),
  group = factor(c(1, 2, 1, 2)),
  upper = c(1.1, 5.3, 3.3, 4.2),
  lower = c(0.8, 4.6, 2.4, 3.6)
)

dodger <- position_dodge(width = 0.75)

gg_blank(df, x = resp, xmin = lower, xmax = upper, y = trt, col = group) +
  geom_col(position = dodger, width = 0.75, alpha = 0.9) +
  geom_errorbar(position = dodger, width = 0.2, col = "#232323")
## {ggblanket} merges col and fill aesthetics into a single col aesthetic

查看函数

能看到查看的函数内的功能也更简单

gg_histogram
## function (data = NULL, x = NULL, y = NULL, col = NULL, facet = NULL, 
##     group = NULL, stat = "bin", position = "stack", pal = NULL, 
##     pal_na = "#7F7F7F", alpha = 0.9, size = 0.5, bins = 40, ..., 
##     title = NULL, subtitle = NULL, coord = ggplot2::coord_cartesian(clip = "off"), 
##     x_breaks = NULL, x_breaks_n = NULL, x_breaks_width = NULL, 
##     x_expand = NULL, x_labels = NULL, x_limits = NULL, x_oob = scales::oob_censor, 
##     x_title = NULL, x_zero = NULL, x_zero_mid = FALSE, y_breaks = NULL, 
##     y_breaks_n = NULL, y_breaks_width = NULL, y_expand = NULL, 
##     y_labels = NULL, y_limits = NULL, y_oob = scales::oob_censor, 
##     y_title = NULL, y_zero = NULL, y_zero_mid = FALSE, col_breaks = NULL, 
##     col_breaks_n = NULL, col_breaks_width = NULL, col_intervals = NULL, 
##     col_labels = NULL, col_legend_place = NULL, col_legend_ncol = NULL, 
##     col_legend_nrow = NULL, col_limits = NULL, col_title = NULL, 
##     facet_intervals = NULL, facet_labels = snakecase::to_sentence_case, 
##     facet_ncol = NULL, facet_nrow = NULL, facet_scales = "fixed", 
##     caption = NULL, theme = NULL) 
## {
##     x <- rlang::enquo(x)
##     y <- rlang::enquo(y)
##     col <- rlang::enquo(col)
##     facet <- rlang::enquo(facet)
##     group <- rlang::enquo(group)
##     if (rlang::is_null(data)) 
##         rlang::abort("data is required")
##     if (!rlang::quo_is_null(col)) 
##         rlang::inform(c(i = "{ggblanket} merges col and fill aesthetics into a single col aesthetic"))
##     if (!rlang::quo_is_null(facet)) 
##         rlang::inform(c(i = "{ggblanket} treats faceting as an aesthetic"))
##     data <- dplyr::ungroup(data)
##     if (rlang::quo_is_null(x)) {
##         if (rlang::is_null(x_title)) {
##             if (stat %in% c("bin", "count")) 
##                 x_title <- "Count"
##         }
##     }
##     else if (rlang::is_null(x_title)) 
##         x_title <- snakecase::to_sentence_case(rlang::as_name(x))
##     if (rlang::quo_is_null(y)) {
##         if (rlang::is_null(y_title)) {
##             if (stat %in% c("bin", "count")) 
##                 y_title <- "Count"
##         }
##     }
##     else if (rlang::is_null(y_title)) 
##         y_title <- snakecase::to_sentence_case(rlang::as_name(y))
##     if (rlang::is_null(theme)) {
##         x_grid <- ifelse(is.numeric(rlang::eval_tidy(x, data)) | 
##             lubridate::is.Date(rlang::eval_tidy(x, data)) | rlang::quo_is_null(x), 
##             TRUE, FALSE)
##         y_grid <- ifelse(is.numeric(rlang::eval_tidy(y, data)) | 
##             lubridate::is.Date(rlang::eval_tidy(y, data)) | rlang::quo_is_null(y), 
##             TRUE, FALSE)
##         theme <- gg_theme(x_grid = x_grid, y_grid = y_grid)
##     }
##     if (rlang::is_null(x_zero)) 
##         x_zero <- FALSE
##     if (rlang::is_null(y_zero)) 
##         y_zero <- FALSE
##     if (!rlang::quo_is_null(x)) {
##         if (is.logical(rlang::eval_tidy(x, data))) {
##             data <- data %>% dplyr::mutate(dplyr::across(!!x, 
##                 ~factor(.x, levels = c("TRUE", "FALSE"))))
##         }
##     }
##     if (!rlang::quo_is_null(y)) {
##         if (is.logical(rlang::eval_tidy(y, data))) {
##             data <- data %>% dplyr::mutate(dplyr::across(!!y, 
##                 ~factor(.x, levels = c("TRUE", "FALSE"))))
##         }
##         if (is.character(rlang::eval_tidy(y, data)) | is.factor(rlang::eval_tidy(y, 
##             data))) {
##             if (!rlang::quo_is_null(col) & (identical(rlang::eval_tidy(y, 
##                 data), rlang::eval_tidy(col, data)))) {
##             }
##             else {
##                 data <- data %>% dplyr::mutate(dplyr::across(!!y, 
##                   ~forcats::fct_rev(.x)))
##             }
##         }
##     }
##     if (!rlang::quo_is_null(col)) {
##         if (is.logical(rlang::eval_tidy(col, data))) {
##             data <- data %>% dplyr::mutate(dplyr::across(!!col, 
##                 ~factor(.x, levels = c("TRUE", "FALSE"))))
##         }
##         if (is.factor(rlang::eval_tidy(col, data)) | is.character(rlang::eval_tidy(col, 
##             data))) {
##             if (is.factor(rlang::eval_tidy(y, data)) | is.character(rlang::eval_tidy(y, 
##                 data))) {
##                 data <- data %>% dplyr::mutate(dplyr::across(!!col, 
##                   ~forcats::fct_rev(.x)))
##             }
##         }
##     }
##     if (!rlang::quo_is_null(facet)) {
##         if (is.logical(class(rlang::eval_tidy(facet, data)))) {
##             data <- data %>% dplyr::mutate(dplyr::across(!!facet, 
##                 ~factor(.x, levels = c("TRUE", "FALSE"))))
##         }
##         if (!rlang::is_null(facet_intervals)) {
##             data <- data %>% dplyr::mutate(dplyr::across(!!facet, 
##                 facet_intervals))
##         }
##     }
##     if (rlang::quo_is_null(col)) {
##         if (rlang::is_null(pal)) 
##             pal <- pal_viridis_mix(1)
##         else pal <- pal[1]
##         col_scale <- ggplot2::scale_colour_manual(values = pal, 
##             na.value = pal_na, aesthetics = c("col", "fill"))
##         col_legend_place <- "n"
##     }
##     else {
##         if (rlang::is_null(col_title)) 
##             col_title <- snakecase::to_sentence_case(rlang::as_name(col))
##         col_title_position <- ifelse(col_title == "", "right", 
##             "top")
##         if (rlang::is_null(col_legend_place)) {
##             if (!rlang::quo_is_null(x) & (identical(rlang::eval_tidy(col, 
##                 data), rlang::eval_tidy(x, data)))) {
##                 col_legend_place <- "n"
##             }
##             else if (!rlang::quo_is_null(y) & (identical(rlang::eval_tidy(col, 
##                 data), rlang::eval_tidy(y, data)))) {
##                 col_legend_place <- "n"
##             }
##             else if (!rlang::quo_is_null(facet) & (identical(rlang::eval_tidy(col, 
##                 data), rlang::eval_tidy(facet, data)))) {
##                 col_legend_place <- "n"
##             }
##             else col_legend_place <- "r"
##         }
##         if (is.numeric(rlang::eval_tidy(col, data))) {
##             if (rlang::is_null(col_intervals)) {
##                 if (rlang::is_null(col_breaks)) {
##                   col_vctr <- dplyr::pull(data, !!col)
##                   col_min_max <- c(min(col_vctr, na.rm = TRUE), 
##                     max(col_vctr, na.rm = TRUE))
##                   if (!rlang::is_null(col_limits)) 
##                     col_min_max <- col_limits
##                   if (!rlang::is_null(col_breaks_width)) {
##                     col_breaks <- scales::fullseq(col_min_max, 
##                       size = col_breaks_width)
##                   }
##                   else {
##                     if (rlang::is_null(col_breaks_n)) {
##                       if (col_legend_place %in% c("b", "t")) 
##                         col_breaks_n <- 3
##                       else col_breaks_n <- 4
##                     }
##                     col_breaks <- pretty(col_min_max, n = col_breaks_n)
##                   }
##                 }
##                 if (rlang::is_null(pal)) 
##                   pal <- viridis::viridis(100)
##                 if (rlang::is_null(col_labels)) 
##                   col_labels <- scales::label_comma()
##                 col_scale <- ggplot2::scale_colour_gradientn(colors = pal, 
##                   labels = col_labels, breaks = col_breaks, limits = col_limits, 
##                   na.value = pal_na, name = col_title, aesthetics = c("col", 
##                     "fill"), guide = ggplot2::guide_colorbar(title.position = col_title_position))
##             }
##             else {
##                 data <- data %>% dplyr::mutate(dplyr::across(!!col, 
##                   col_intervals))
##                 col_levels <- levels(rlang::eval_tidy(col, data))
##                 col_n <- length(col_levels)
##                 if (rlang::is_null(pal)) 
##                   pal <- pal_viridis_mix(col_n)
##                 else pal <- pal[1:col_n]
##                 if (is.numeric(rlang::eval_tidy(y, data)) | lubridate::is.Date(rlang::eval_tidy(y, 
##                   data))) {
##                   if (col_legend_place %in% c("b", "t")) 
##                     col_legend_rev <- FALSE
##                   else col_legend_rev <- TRUE
##                 }
##                 else if (is.factor(rlang::eval_tidy(y, data)) | 
##                   is.character(rlang::eval_tidy(y, data))) {
##                   if (col_legend_place %in% c("b", "t")) 
##                     col_legend_rev <- TRUE
##                   else col_legend_rev <- FALSE
##                   pal <- rev(pal)
##                 }
##                 else col_legend_rev <- FALSE
##                 if (rlang::is_null(col_breaks)) 
##                   col_breaks <- ggplot2::waiver()
##                 if (rlang::is_null(col_labels)) 
##                   col_labels <- ggplot2::waiver()
##                 col_scale <- ggplot2::scale_colour_manual(values = pal, 
##                   breaks = col_levels, limits = col_levels, labels = col_labels, 
##                   na.value = pal_na, name = col_title, aesthetics = c("col", 
##                     "fill"), guide = ggplot2::guide_legend(reverse = col_legend_rev, 
##                     title.position = col_title_position, ncol = col_legend_ncol, 
##                     nrow = col_legend_nrow, byrow = TRUE))
##             }
##         }
##         else {
##             if (!rlang::is_null(col_limits)) 
##                 col_n <- length(col_limits)
##             else if (!rlang::is_null(col_breaks)) 
##                 col_n <- length(col_breaks)
##             else {
##                 if (is.factor(rlang::eval_tidy(col, data))) {
##                   col_n <- length(levels(rlang::eval_tidy(col, 
##                     data)))
##                 }
##                 else col_n <- length(unique(rlang::eval_tidy(col, 
##                   data)))
##             }
##             if (rlang::is_null(pal)) 
##                 pal <- pal_d3_mix(col_n)
##             else pal <- pal[1:col_n]
##             if (is.numeric(rlang::eval_tidy(y, data)) | lubridate::is.Date(rlang::eval_tidy(y, 
##                 data))) {
##                 if (is.factor(rlang::eval_tidy(col, data)) | 
##                   is.character(rlang::eval_tidy(col, data))) {
##                   col_legend_rev <- FALSE
##                 }
##                 else if (col_legend_place %in% c("b", "t")) 
##                   col_legend_rev <- FALSE
##                 else col_legend_rev <- TRUE
##             }
##             else if (is.factor(rlang::eval_tidy(y, data)) | is.character(rlang::eval_tidy(y, 
##                 data))) {
##                 if (is.factor(rlang::eval_tidy(col, data)) | 
##                   is.character(rlang::eval_tidy(col, data))) {
##                   col_legend_rev <- TRUE
##                 }
##                 else if (col_legend_place %in% c("b", "t")) 
##                   col_legend_rev <- TRUE
##                 else col_legend_rev <- FALSE
##                 pal <- rev(pal)
##             }
##             else col_legend_rev <- FALSE
##             if (rlang::is_null(col_breaks)) 
##                 col_breaks <- ggplot2::waiver()
##             if (rlang::is_null(col_labels)) 
##                 col_labels <- snakecase::to_sentence_case
##             col_scale <- ggplot2::scale_colour_manual(values = pal, 
##                 breaks = col_breaks, limits = col_limits, labels = col_labels, 
##                 na.value = pal_na, name = col_title, aesthetics = c("col", 
##                   "fill"), guide = ggplot2::guide_legend(reverse = col_legend_rev, 
##                   title.position = col_title_position, ncol = col_legend_ncol, 
##                   nrow = col_legend_nrow, byrow = TRUE))
##         }
##     }
##     if (!rlang::quo_is_null(x) & !rlang::quo_is_null(y)) {
##         if (!rlang::quo_is_null(col)) {
##             plot <- data %>% ggplot2::ggplot(mapping = ggplot2::aes(x = !!x, 
##                 y = !!y, col = !!col, fill = !!col, group = !!group))
##         }
##         else if (rlang::quo_is_null(col)) {
##             plot <- data %>% ggplot2::ggplot(mapping = ggplot2::aes(x = !!x, 
##                 y = !!y, col = "", fill = "", group = !!group))
##         }
##     }
##     else if (!rlang::quo_is_null(x) & rlang::quo_is_null(y)) {
##         if (!rlang::quo_is_null(col)) {
##             plot <- data %>% ggplot2::ggplot(mapping = ggplot2::aes(x = !!x, 
##                 col = !!col, fill = !!col, group = !!group))
##         }
##         else if (rlang::quo_is_null(col)) {
##             plot <- data %>% ggplot2::ggplot(mapping = ggplot2::aes(x = !!x, 
##                 col = "", fill = "", group = !!group))
##         }
##     }
##     else if (rlang::quo_is_null(x) & !rlang::quo_is_null(y)) {
##         if (!rlang::quo_is_null(col)) {
##             plot <- data %>% ggplot2::ggplot(mapping = ggplot2::aes(y = !!y, 
##                 col = !!col, fill = !!col, group = !!group))
##         }
##         else if (rlang::quo_is_null(col)) {
##             plot <- data %>% ggplot2::ggplot(mapping = ggplot2::aes(y = !!y, 
##                 col = "", fill = "", group = !!group))
##         }
##     }
##     else if (rlang::quo_is_null(x) & rlang::quo_is_null(y)) {
##         if (!rlang::quo_is_null(col)) {
##             plot <- data %>% ggplot2::ggplot(mapping = ggplot2::aes(col = !!col, 
##                 fill = !!col, group = !!group))
##         }
##         else if (rlang::quo_is_null(col)) {
##             plot <- data %>% ggplot2::ggplot(mapping = ggplot2::aes(col = "", 
##                 fill = "", group = !!group))
##         }
##     }
##     plot <- plot + ggplot2::geom_histogram(stat = stat, position = position, 
##         alpha = alpha, size = size, bins = bins, ...)
##     if (!rlang::quo_is_null(facet)) {
##         if (!rlang::is_null(facet_intervals)) {
##             plot <- plot + ggplot2::facet_wrap(ggplot2::vars(!!facet), 
##                 scales = facet_scales, ncol = facet_ncol, nrow = facet_nrow)
##         }
##         else {
##             plot <- plot + ggplot2::facet_wrap(ggplot2::vars(!!facet), 
##                 labeller = ggplot2::as_labeller(facet_labels), 
##                 scales = facet_scales, ncol = facet_ncol, nrow = facet_nrow)
##         }
##     }
##     if (!rlang::quo_is_null(x) & rlang::quo_is_null(y)) {
##         if (is.character(rlang::eval_tidy(x, data)) | is.factor(rlang::eval_tidy(x, 
##             data))) {
##             if (rlang::is_null(x_expand)) 
##                 x_expand <- ggplot2::waiver()
##             if (rlang::is_null(x_labels)) 
##                 x_labels <- snakecase::to_sentence_case
##             x_scale <- ggplot2::scale_x_discrete(expand = x_expand, 
##                 labels = x_labels)
##         }
##         else {
##             if (facet_scales %in% c("fixed", "free_y")) {
##                 x_vctr <- dplyr::pull(data, !!x)
##                 x_min <- min(x_vctr, na.rm = TRUE)
##                 x_max <- max(x_vctr, na.rm = TRUE)
##                 if (rlang::is_null(x_breaks)) {
##                   x_min_max <- c(x_min, x_max)
##                   if (x_zero) 
##                     x_min_max <- c(0, x_min_max)
##                   if (x_zero_mid) 
##                     x_min_max <- c(-x_min_max, x_min_max)
##                   if (!rlang::is_null(x_limits) & !any(is.na(x_limits))) 
##                     x_min_max <- x_limits
##                   if (!rlang::is_null(x_breaks_width)) {
##                     x_breaks <- scales::fullseq(x_min_max, size = x_breaks_width)
##                   }
##                   else {
##                     if (rlang::is_null(x_breaks_n)) {
##                       x_breaks_n <- ifelse(rlang::quo_is_null(facet), 
##                         5, 3)
##                     }
##                     x_breaks <- pretty(x_min_max, n = x_breaks_n)
##                   }
##                 }
##                 if (rlang::is_null(x_limits)) 
##                   x_limits <- c(min(x_breaks), max(x_breaks))
##                 if (rlang::is_null(x_expand)) 
##                   x_expand <- c(0, 0)
##             }
##             else if (facet_scales %in% c("free", "free_x")) {
##                 if (rlang::is_null(x_breaks)) 
##                   x_breaks <- ggplot2::waiver()
##                 x_limits <- NULL
##                 if (rlang::is_null(x_expand)) 
##                   x_expand <- ggplot2::waiver()
##             }
##             if (rlang::is_null(x_labels)) {
##                 if (is.numeric(rlang::eval_tidy(x, data)) | rlang::quo_is_null(x)) 
##                   x_labels <- scales::label_comma()
##                 else if (lubridate::is.Date(rlang::eval_tidy(x, 
##                   data))) 
##                   x_labels <- scales::label_date_short()
##                 else x_labels <- ggplot2::waiver()
##             }
##             if (is.numeric(rlang::eval_tidy(x, data)) | rlang::quo_is_null(x)) {
##                 x_scale <- ggplot2::scale_x_continuous(breaks = x_breaks, 
##                   limits = x_limits, expand = x_expand, labels = x_labels, 
##                   oob = x_oob)
##             }
##             else if (lubridate::is.Date(rlang::eval_tidy(x, data))) {
##                 x_scale <- ggplot2::scale_x_date(breaks = x_breaks, 
##                   limits = x_limits, expand = x_expand, labels = x_labels, 
##                   oob = x_oob)
##             }
##         }
##         plot <- plot + x_scale
##     }
##     if (!rlang::quo_is_null(y) & rlang::quo_is_null(x)) {
##         if (is.character(rlang::eval_tidy(y, data)) | is.factor(rlang::eval_tidy(y, 
##             data))) {
##             if (rlang::is_null(y_expand)) 
##                 y_expand <- ggplot2::waiver()
##             if (rlang::is_null(y_labels)) 
##                 y_labels <- snakecase::to_sentence_case
##             y_scale <- ggplot2::scale_y_discrete(expand = y_expand, 
##                 labels = y_labels)
##         }
##         else {
##             if (facet_scales %in% c("fixed", "free_x")) {
##                 y_vctr <- dplyr::pull(data, !!y)
##                 y_min <- min(y_vctr, na.rm = TRUE)
##                 y_max <- max(y_vctr, na.rm = TRUE)
##                 if (rlang::is_null(y_breaks)) {
##                   y_min_max <- c(y_min, y_max)
##                   if (y_zero) 
##                     y_min_max <- c(0, y_min_max)
##                   if (y_zero_mid) 
##                     y_min_max <- c(-y_min_max, y_min_max)
##                   if (!rlang::is_null(y_limits) & !any(is.na(y_limits))) 
##                     y_min_max <- y_limits
##                   if (!rlang::is_null(y_breaks_width)) {
##                     y_breaks <- scales::fullseq(y_min_max, size = y_breaks_width)
##                   }
##                   else {
##                     if (rlang::is_null(y_breaks_n)) {
##                       y_breaks_n <- ifelse(rlang::quo_is_null(facet), 
##                         5, 4)
##                     }
##                     y_breaks <- pretty(y_min_max, n = y_breaks_n)
##                   }
##                 }
##                 if (rlang::is_null(y_limits)) 
##                   y_limits <- c(min(y_breaks), max(y_breaks))
##                 if (rlang::is_null(y_expand)) 
##                   y_expand <- c(0, 0)
##             }
##             else if (facet_scales %in% c("free", "free_y")) {
##                 if (rlang::is_null(y_breaks)) 
##                   y_breaks <- ggplot2::waiver()
##                 y_limits <- NULL
##                 if (rlang::is_null(y_expand)) 
##                   y_expand <- ggplot2::waiver()
##             }
##             if (rlang::is_null(y_labels)) {
##                 if (is.numeric(rlang::eval_tidy(y, data)) | rlang::quo_is_null(y)) 
##                   y_labels <- scales::label_comma()
##                 else if (lubridate::is.Date(rlang::eval_tidy(y, 
##                   data))) 
##                   y_labels <- scales::label_date_short()
##                 else y_labels <- ggplot2::waiver()
##             }
##             if (is.numeric(rlang::eval_tidy(y, data)) | rlang::quo_is_null(y)) {
##                 y_scale <- ggplot2::scale_y_continuous(breaks = y_breaks, 
##                   limits = y_limits, expand = y_expand, labels = y_labels, 
##                   oob = y_oob)
##             }
##             else if (lubridate::is.Date(rlang::eval_tidy(y, data))) {
##                 y_scale <- ggplot2::scale_y_date(breaks = y_breaks, 
##                   limits = y_limits, expand = y_expand, labels = y_labels, 
##                   oob = y_oob)
##             }
##         }
##         plot <- plot + y_scale
##     }
##     layer_data <- ggplot2::layer_data(plot)
##     if (is.character(rlang::eval_tidy(x, data)) | is.factor(rlang::eval_tidy(x, 
##         data))) {
##         if (rlang::is_null(x_expand)) 
##             x_expand <- ggplot2::waiver()
##         if (rlang::is_null(x_labels)) 
##             x_labels <- snakecase::to_sentence_case
##         x_scale <- ggplot2::scale_x_discrete(expand = x_expand, 
##             labels = x_labels)
##     }
##     else {
##         if (facet_scales %in% c("fixed", "free_y")) {
##             x_vctr <- layer_data %>% dplyr::select(tidyselect::matches(stringr::regex("^x$|^xmin$|^xmax$|^xend$|^xmax_final$"))) %>% 
##                 tidyr::pivot_longer(cols = tidyselect::everything()) %>% 
##                 dplyr::pull(.data$value)
##             if (lubridate::is.Date(rlang::eval_tidy(x, data))) {
##                 x_vctr <- as.Date(x_vctr, origin = "1970-01-01")
##             }
##             x_min <- min(x_vctr, na.rm = TRUE)
##             x_max <- max(x_vctr, na.rm = TRUE)
##             if (rlang::is_null(x_breaks)) {
##                 x_min_max <- c(x_min, x_max)
##                 if (x_zero) 
##                   x_min_max <- c(0, x_min_max)
##                 if (x_zero_mid) 
##                   x_min_max <- c(-x_min_max, x_min_max)
##                 if (!rlang::is_null(x_breaks_width)) {
##                   x_breaks <- scales::fullseq(x_min_max, size = x_breaks_width)
##                 }
##                 else {
##                   if (rlang::is_null(x_breaks_n)) {
##                     x_breaks_n <- ifelse(rlang::quo_is_null(facet), 
##                       5, 3)
##                   }
##                   x_breaks <- pretty(x_min_max, n = x_breaks_n)
##                 }
##             }
##             if (length(class(position)) == 1) {
##                 if (position == "fill") 
##                   x_limits <- c(NA, NA)
##             }
##             else if (class(position)[1] == "PositionFill") {
##                 x_limits <- c(NA, NA)
##             }
##             if (rlang::is_null(x_limits)) 
##                 x_limits <- c(min(x_breaks), max(x_breaks))
##             if (rlang::is_null(x_expand)) 
##                 x_expand <- c(0, 0)
##         }
##         else if (facet_scales %in% c("free", "free_x")) {
##             if (rlang::is_null(x_breaks)) 
##                 x_breaks <- ggplot2::waiver()
##             x_limits <- NULL
##             if (rlang::is_null(x_expand)) 
##                 x_expand <- ggplot2::waiver()
##         }
##         if (rlang::is_null(x_labels)) {
##             if (is.numeric(rlang::eval_tidy(x, data)) | rlang::quo_is_null(x)) 
##                 x_labels <- scales::label_comma()
##             else if (lubridate::is.Date(rlang::eval_tidy(x, data))) 
##                 x_labels <- scales::label_date_short()
##             else x_labels <- ggplot2::waiver()
##         }
##         if (is.numeric(rlang::eval_tidy(x, data)) | rlang::quo_is_null(x)) {
##             x_scale <- ggplot2::scale_x_continuous(breaks = x_breaks, 
##                 limits = x_limits, expand = x_expand, labels = x_labels, 
##                 oob = x_oob)
##         }
##         else if (lubridate::is.Date(rlang::eval_tidy(x, data))) {
##             x_scale <- ggplot2::scale_x_date(breaks = x_breaks, 
##                 limits = x_limits, expand = x_expand, labels = x_labels, 
##                 oob = x_oob)
##         }
##     }
##     plot <- plot + x_scale
##     if (is.character(rlang::eval_tidy(y, data)) | is.factor(rlang::eval_tidy(y, 
##         data))) {
##         if (rlang::is_null(y_expand)) 
##             y_expand <- ggplot2::waiver()
##         if (rlang::is_null(y_labels)) 
##             y_labels <- snakecase::to_sentence_case
##         y_scale <- ggplot2::scale_y_discrete(expand = y_expand, 
##             labels = y_labels)
##     }
##     else {
##         if (facet_scales %in% c("fixed", "free_x")) {
##             y_vctr <- layer_data %>% dplyr::select(tidyselect::matches(stringr::regex("^y$|^ymin$|^ymax$|^yend$|^ymax_final$"))) %>% 
##                 tidyr::pivot_longer(cols = tidyselect::everything()) %>% 
##                 dplyr::pull(.data$value)
##             if (lubridate::is.Date(rlang::eval_tidy(y, data))) {
##                 y_vctr <- as.Date(y_vctr, origin = "1970-01-01")
##             }
##             y_min <- min(y_vctr, na.rm = TRUE)
##             y_max <- max(y_vctr, na.rm = TRUE)
##             if (rlang::is_null(y_breaks)) {
##                 y_min_max <- c(y_min, y_max)
##                 if (y_zero) 
##                   y_min_max <- c(0, y_min_max)
##                 if (y_zero_mid) 
##                   y_min_max <- c(-y_min_max, y_min_max)
##                 if (!rlang::is_null(y_limits) & !any(is.na(y_limits))) 
##                   y_min_max <- y_limits
##                 if (!rlang::is_null(y_breaks_width)) {
##                   y_breaks <- scales::fullseq(y_min_max, size = y_breaks_width)
##                 }
##                 else {
##                   if (rlang::is_null(y_breaks_n)) {
##                     y_breaks_n <- ifelse(rlang::quo_is_null(facet), 
##                       5, 4)
##                   }
##                   y_breaks <- pretty(y_min_max, n = y_breaks_n)
##                 }
##             }
##             if (length(class(position)) == 1) {
##                 if (position == "fill") 
##                   y_limits <- c(NA, NA)
##             }
##             else if (class(position)[1] == "PositionFill") {
##                 y_limits <- c(NA, NA)
##             }
##             if (rlang::is_null(y_limits)) 
##                 y_limits <- c(min(y_breaks), max(y_breaks))
##             if (rlang::is_null(y_expand)) 
##                 y_expand <- c(0, 0)
##         }
##         else if (facet_scales %in% c("free", "free_y")) {
##             if (rlang::is_null(y_breaks)) 
##                 y_breaks <- ggplot2::waiver()
##             y_limits <- NULL
##             if (rlang::is_null(y_expand)) 
##                 y_expand <- ggplot2::waiver()
##         }
##         if (rlang::is_null(y_labels)) {
##             if (is.numeric(rlang::eval_tidy(y, data)) | rlang::quo_is_null(y)) 
##                 y_labels <- scales::label_comma()
##             else if (lubridate::is.Date(rlang::eval_tidy(y, data))) 
##                 y_labels <- scales::label_date_short()
##             else y_labels <- ggplot2::waiver()
##         }
##         if (is.numeric(rlang::eval_tidy(y, data)) | rlang::quo_is_null(y)) {
##             y_scale <- ggplot2::scale_y_continuous(breaks = y_breaks, 
##                 limits = y_limits, expand = y_expand, labels = y_labels, 
##                 oob = y_oob)
##         }
##         else if (lubridate::is.Date(rlang::eval_tidy(y, data))) {
##             y_scale <- ggplot2::scale_y_date(breaks = y_breaks, 
##                 limits = y_limits, expand = y_expand, labels = y_labels, 
##                 oob = y_oob)
##         }
##     }
##     plot <- plot + y_scale
##     plot <- plot + col_scale + coord + ggplot2::labs(title = title, 
##         subtitle = subtitle, x = x_title, y = y_title, caption = caption) + 
##         theme
##     if (col_legend_place == "b") {
##         plot <- plot + ggplot2::theme(legend.direction = "horizontal") + 
##             ggplot2::theme(legend.position = "bottom")
##     }
##     else if (col_legend_place == "t") {
##         plot <- plot + ggplot2::theme(legend.direction = "horizontal") + 
##             ggplot2::theme(legend.position = "top")
##     }
##     else if (col_legend_place == "n" | rlang::quo_is_null(col)) {
##         plot <- plot + ggplot2::theme(legend.position = "none")
##     }
##     else if (col_legend_place == "l") {
##         plot <- plot + ggplot2::theme(legend.position = "left")
##     }
##     return(plot)
## }
## <bytecode: 0x7fea0e508848>
## <environment: namespace:ggblanket>

这样的就很不清楚

geom_col
## function (mapping = NULL, data = NULL, position = "stack", ..., 
##     width = NULL, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) 
## {
##     layer(data = data, mapping = mapping, stat = "identity", 
##         geom = GeomCol, position = position, show.legend = show.legend, 
##         inherit.aes = inherit.aes, params = list(width = width, 
##             na.rm = na.rm, ...))
## }
## <bytecode: 0x7fea11bcfd28>
## <environment: namespace:ggplot2>

最后一次修改于 2022-05-15