ggplot中的两行X轴标签 [英] Two lines of X axis labels in ggplot
本文介绍了ggplot中的两行X轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在ggplot中制作两行X轴标签.
I want to make two lines of X axis labels in ggplot.
在此绘图中,我想在每个指定年份的下方添加一行标签.
In this plot, I want to add one more line of label below each specified year. Something like
1990 1995 2000 2005 2010
cold warm warm cold warm
1990 1995 2000 2005 2010
cold warm warm cold warm
这是我制作这张图的代码
This is my code for making this plot
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 any way to make one more line of label by creating a column specifically for the labels?
谢谢!
推荐答案
您只需通过scale_x_continuous
(或scale_x_date
,如果它实际上是Date
格式)添加自定义标签.
You can just add custom labels via scale_x_continuous
(or scale_x_date
, if it is actually in Date
format).
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'))
这篇关于ggplot中的两行X轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文