2016-12-14 123 views
2

,我有以下的數據幀:添加日期作爲標籤,ggplot facet_grid

Date K Row Col Downward_solar_radiation Solar_radiation_calc 
1 2014-01-02 1 1 1      0     0 
2 2014-01-02 2 1 1      0     0 
3 2014-01-02 3 1 1      0     0 
4 2014-01-02 4 1 1      0     0 
5 2014-01-02 5 1 1      0     0 
6 2014-01-02 6 1 1      0     0 

數據幀中包含30個不同日期的數據。 我使用下面的代碼片段生產地塊,每一個日期,排列成網格:

df %>% 
    ggplot(aes(x=K)) + 
    geom_line(aes(y=Downward_solar_radiation), color="red") + 
    geom_line(aes(y=Solar_radiation_calc), color="blue")+ 
    facet_grid(Col~Row) 

產生的情節是:

enter image description here

我想一個文本添加到每個情節描繪相應的日期和擺脫標籤1-6。

+0

爲什麼不使用facet_grid(Date〜Row) – MLavoie

回答

1

您可以使用facet_wrap(~ Date, nrow=5)而不是facet_grid。這樣,您不需要手動上下文標籤和行標籤,ggplot會自動標記每個方面的相應日期。 Documentation & examples