我想在ggplot中制作两行X轴标签.

在这个图中,我想在每个指定年份下面再添加一行标签.就像是
1990 1995 2000 2005 2010
cold warm warm cold warm
这是我制作这个情节的代码
ggplot(subset(dat, countryid %in% c("1")), aes(date,
nonpartisan))+geom_line(aes(color=countryid), color="dodgerblue1",
size=1.4)+geom_line(aes(date, reshuffle), color="gray")+ theme_bw()
Run Code Online (Sandbox Code Playgroud)
有没有办法通过专门为标签创建一个列来创建一个标签行?
谢谢!
您可以通过scale_x_continuous(或者scale_x_date,如果它实际上是Date格式)添加自定义标签.
ggplot(subset(dat, countryid %in% c("1")), aes(date, nonpartisan)) +
geom_line(aes(color=countryid), color="dodgerblue1", size=1.4) +
geom_line(aes(date, reshuffle), color="gray") +
theme_bw() +
scale_x_continuous(name = 'date',
breaks = c('1990', '1995', '2000', '2005', '2010'),
labels = c('1990\ncold', '1995\nwarm', '2000\nwarm', '2005\ncold', '2010\nwarm'))
Run Code Online (Sandbox Code Playgroud)