[英]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.我有一个
facet
ed ggplot
,其中每个方面都是一个月中的一天。 I want to replace days 4 through 29 with space and three dots (ellipsis) to remind my reader about the omitted days.我想用空格和三个点(省略号)替换第 4 天到第 29 天,以提醒我的读者注意省略的天数。 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.我看到
theme()
允许自定义,但我没有看到任何选项可以让我在第 3 天和第 30 天之间插入空格和三个点。
Should I resort to Photoshop or MS Paint?我应该求助于 Photoshop 还是 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)由代表 package (v0.3.0) 于 2019 年 11 月 13 日创建
Here's an option making day
a factor
:这是一个使
day
成为一个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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.