使用以下数据和代码,我生成了三个相互重叠的折线图。我想将“ Total Breeding Pairs”和“ Total Chicks Banded”组合到一个只覆盖“%Chicks Banded ..”的第二张图上的图中。
我已经进行了快速搜索,发现了Cowplot,但似乎并排堆叠了它,并且我需要x轴来对齐这两个图。
我的代码:
ggplot(data = `meltedInd`, mapping = aes(x = Year, y = value)) +
geom_line(aes(color = variable), size = 1) +
scale_color_manual(values = c("deepskyblue", "firebrick1", "limegreen")) +
theme_minimal() +
xlab("Year") + ylab("") + ggtitle("") +
scale_x_continuous(breaks=c(1985,1990,1995,2000,2005,2010,2015,2020),
limits = c(1986,2017)) +
facet_grid(variable ~ ., scales = "free_y") +
theme(legend.position = "none")
我的数据示例:
Year variable value
1986 Total Breeding Pairs NA
1987 Total Breeding Pairs 1000
1988 Total Breeding Pairs 2200
1989 Total Breeding Pairs 2150
1986 Total Chicks Banded 484
1987 Total Chicks Banded 551
1988 Total Chicks Banded 1498
1989 Total Chicks Banded 1609
1986 % Chicks Banded per Pair NA
1987 % Chicks Banded per Pair 55.10
1988 % Chicks Banded per Pair 68.09
1989 % Chicks Banded per Pair 74.84