我使用以下命令将 y 轴点映射到 x 轴geom_segment()
然后使用facet_wrap
将数据分成两个图;然而,y 轴点都显示在这两个图上。
我怎样才能只拥有与每个相关的必要的 y 轴点facet_wrap
?
示例代码
dat <- structure(list(temp = c(1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3,
4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5), rev = c(-5,
-11, -20, -29, -40, -9, -20, -32, -45, -57, -12, -24, -37, -50,
-62, -7, -20, -36, -52, -67, -5, -13, -23, -35, -47, -12, -24,
-36, -48, -58), type = c("Type 1", "Type 1", "Type 1", "Type 1",
"Type 1", "Type 1", "Type 1", "Type 1", "Type 1", "Type 1", "Type 1",
"Type 1", "Type 1", "Type 1", "Type 1", "Type 2", "Type 2", "Type 2",
"Type 2", "Type 2", "Type 2", "Type 2", "Type 2", "Type 2", "Type 2",
"Type 2", "Type 2", "Type 2", "Type 2", "Type 2"), model = c("A",
"A", "A", "A", "A", "B", "B", "B", "B", "B", "C", "C", "C", "C",
"C", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "C", "C",
"C", "C", "C")), .Names = c("temp", "rev", "type", "model"), row.names = c(NA,
-30L), class = "data.frame")
p1 <- ggplot(dat, aes(temp, rev, color = model)) +
geom_line() + geom_point() + geom_segment(aes(x = 0, xend = temp, yend = rev), linetype = "dashed", color = "grey") +
facet_wrap(~type, scales = "free") + scale_y_continuous(breaks = dat$rev)
p1
Plot