简体   繁体   中英

Add space and three dots (ellipsis) between ggplot2 facets to indicate omitted facets

I have a facet ed ggplot where each facet is a day of the month. I want to replace days 4 through 29 with space and three dots (ellipsis) to remind my reader about the omitted days. I see that theme() allows customization, but I do not see any options that would allow me to insert space and three dots between day 3 and day 30 facets.

Should I resort to Photoshop or MS Paint?

library(tidyverse)

tibble(day = rep(1:30, 5), value = runif(5*30)) %>% 
    filter(day %in% c(1:3, 30)) %>% 
    ggplot(aes(x = value)) +
    geom_histogram() +
    facet_grid(day ~ .)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Created on 2019-11-13 by the reprex package (v0.3.0)

Here's an option making day a factor :

library(ggplot2)
library(dplyr)

tibble(day = rep(1:30, 5), value = runif(5*30)) %>% 
  filter(day %in% c(1:3, 30)) %>% 
  mutate(day = factor(day, levels = c('1','2','3','...','30')))%>% #new
  ggplot(aes(x = value)) +
  geom_histogram() +
  facet_grid(day ~ ., drop = F) #added drop = F

ggplot未使用的方面因子

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM