可能可以使用填充和alpha的某种组合来显示底层重叠。这是一个主意:
ggplot(df %>%
mutate(n = 1:n()),
aes(xmin = start,
ymin = as.numeric(chr) - 0.1,
xmax = stop,
ymax = as.numeric(chr) + 0.1)) +
xlab("position") +
geom_rect(color = "black", alpha = 0.5) +
scale_y_continuous(breaks = c(1, 2),
labels = levels(df$chr))+
theme(legend.position = "none",
text = element_text(size = 10)) +
theme_bw()
区域越暗,重叠越多。如果重叠很少,这可能很方便,但如果有很多重叠,我会强调如下:
ggplot(df %>%
group_by(chr) %>%
mutate(n = 1:n()),
aes(xmin = start,
ymin = n - 0.5,
xmax = stop,
ymax = n + 0.5)) +
xlab("position") +
geom_rect(color = "black", alpha = 0.5) +
facet_wrap(~chr, ncol = 1, strip.position = "right")+
theme_bw() +
theme(legend.position = "none",
axis.text.y = element_blank(),
axis.ticks.y = element_blank())
structure(list(chr = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L), .Label = c("a", "b"), class = "factor"), start = c(3L, 6L,
5L, 12L, 6L, 3L, 2L, 2L), stop = c(7L, 8L, 10L, 14L, 8L, 8L,
5L, 5L)), .Names = c("chr", "start", "stop"), class = "data.frame", row.names = c(NA,
-8L))