2014-12-11 5 views
2

gplot에서 두 줄의 X 축 레이블을 만들고 싶습니다. 이 도표에서 ggplot의 두 줄 X 축 레이블

enter image description here

, 나는 각각의 지정된 연도 아래 라벨의 또 하나의 줄을 추가합니다.

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() 

레이블을 위해 특별히 열을 생성하여 라벨의 또 하나 개의 라인을 만들 수있는 방법이 있나요를 만들기위한 내 코드?

감사합니다.

+0

[ggplot 라인 차트 다열 X 축 라벨 (가능 중복 http://stackoverflow.com/questions/20571306/multi-row-x-axis-labels-in-ggplot-line -chart) – Henrik

답변

7

scale_x_continuous (또는 실제로는 Date 형식 인 경우 scale_x_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')) 
+0

고마워! 이것은 완벽하게 작동합니다. 나는 여러분의 코드를'scale_x_continuous'에서'scale_x_date'로 수정했습니다. 휴식을위한 사소한 수정. – user3077008

+0

@ user3077008 결과 코드를 게시 할 수 있습니까? 감사 – xhie