我通常必须创建与以下相似的图。结果使我有些恼怒的是刻面B中条的位置和大小/(bin)宽度。
理想情况下,我想使小节与小平面A中的c的杆位于同一水平/高度,并且剩余的两个“空格”(a和b位于小面A中)在小平面B中保持空白。
library(tidyverse)
df <- tibble::tribble(
~group, ~unit, ~value,
"A", "a", 10L,
"A", "b", 15L,
"A", "c", 20L,
"A", "c", 25L,
"B", "d", 10L
)
df %>%
ggplot()+
geom_bar(aes(x=unit,
y=value),
stat="identity")+
facet_wrap(vars(group),
scales = "free_y")+
coord_flip()
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLmltZ3VyLmNvbS8weXBwMHd0LnBuZyJ9” alt =“”>
由reprex package(v0.3.0)在2020-05-26创建
[我知道我可以使用scales="free"
或使用patchwork
,cowplot
包等。但是据我所知,这些方法都无法产生期望的结果。
有什么想法吗?非常感谢!