r_eda

Histogram 图 Zoom 功能

Jiaxiang Li 2019-03-12

参考 www.data-imaginist.com

library(ggforce)
## Loading required package: ggplot2
suppressMessages(library(tidyverse))
ggplot() + 
  geom_histogram(aes(x = price), dplyr::mutate(diamonds, z = FALSE), bins = 50) + 
  geom_histogram(aes(x = price), dplyr::mutate(diamonds, z = TRUE), bins = 500) + 
  facet_zoom(xlim = c(3000, 5000), ylim = c(0, 300), zoom.data = z,
             horizontal = FALSE) + 
  theme(zoom.y = element_blank(), validate = FALSE)

增加 z 列是因为 zoom 前后的bin的值不同,需要进行区分。