如何在ggplot2中更改插值/平滑geom_raster

时间:2018-06-15 18:35:03

标签: r ggplot2

是否可以更改geom_raster中的插值级别(例如平滑,模糊)?

library(tidyverse)

mtcars %>%
  group_by(carb, hp = cut(mtcars$hp, 3, labels = c("low", "med", "hi"))) %>%
  summarise(mean_mpg = mean(mpg)) %>%
  ggplot(aes(carb, hp)) +
  geom_raster(aes(fill = mean_mpg), interpolate = FALSE) +
  scale_fill_viridis_c(option = "inferno")

enter image description here

我想控制下图中发生的模糊程度:

mtcars %>%
  group_by(carb, hp = cut(mtcars$hp, 3, labels = c("low", "med", "hi"))) %>%
  summarise(mean_mpg = mean(mpg)) %>%
  ggplot(aes(carb, hp)) +
  geom_raster(aes(fill = mean_mpg), interpolate = TRUE) +
  scale_fill_viridis_c(option = "inferno")

enter image description here

我知道如何使用stat_density_2d - see this post执行此操作 - 但我想通过填充计算值而不是计算密度。

0 个答案:

没有答案