Two lines of X-axis labels in ggplot
I want to make two lines of X axis labels in ggplot.
In this graph, I want to add another label line below each specified year. Something like
1990 1995 2000 2005 2010
cold warm warm cold warm
This is my code for creating this graph
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()
Is there a way to make another label line by creating a column specifically for labels?
Thank!
+3
source to share
1 answer
You can just add custom shortcuts via scale_x_continuous
(or scale_x_date
if it really is in the format 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'))
+8
source to share