2015-10-19 51 views
0

我有一個geom_area情節,看起來像這樣填:geom_area組和不同的變量

enter image description here

x軸是時間序列,我要的顏色各方面的按組的填充變量「estacion」(一年的季節)。這是我的數據樣本:

año  censo  estacion  tipoEuro  censEu censTot  pCensEu 
2010 2010-01-01 Invierno HA frisona   13  32  40.62500 
2010 2010-01-01 Invierno Bovinos jovenes  10  32  31.25000 
2010 2010-01-02 Invierno HA frisona   13  32  40.62500 
--- 
2014 2014-12-30 Invierno Bovinos jovenes  15  26  57.69231 
2014 2014-12-31 Invierno HA frisona   3  26  11.53846 
2014 2014-12-31 Invierno Terneros    8  26  30.76923 

這裏的我使用,使劇情代碼:

ggplot(censTot1,aes(x=censo, y=pCensEu,group=tipoEuro)) + 
    geom_area() + 
    geom_line()+ facet_grid(tipoEuro ~ .) 

,這是我打算使用的代碼,並生成該錯誤:

ggplot(censTot1,aes(x=censo,y=pCensEu,group=tipoEuro,fill=estacion)) + 
    geom_area() + 
    geom_line()+ facet_grid(tipoEuro ~ .) 

Error: Aesthetics can not vary with a ribbon

回答

0

我不確定所需的輸出。這會解決你的問題嗎?

library(ggplot2) 
ggplot(df, aes(x=censo, y=pCensEu,group=tipoEuro))+ 
    geom_area(aes(fill=estacion))+ 
    geom_line()+ 
    facet_grid(tipoEuro ~ .) 

數據使用

df <- structure(list(año = c(2010L, 2010L, 2010L, 2014L, 2014L, 2014L 
), censo = structure(c(1L, 1L, 2L, 3L, 4L, 4L), .Label = c("01/01/2010", 
"02/01/2010", "30/12/2014", "31/12/2014"), class = "factor"), 
    estacion = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = "Invierno", class = "factor"), 
    tipoEuro = structure(c(2L, 1L, 2L, 1L, 2L, 3L), .Label = c("Bovinos jovenes", 
    "HA frisona", "Terneros"), class = "factor"), censEu = c(13L, 
    10L, 13L, 15L, 3L, 8L), censTot = c(32L, 32L, 32L, 26L, 26L, 
    26L), pCensEu = c(40.625, 31.25, 40.625, 57.69231, 11.53846, 
    30.76923)), .Names = c("año", "censo", "estacion", "tipoEuro", 
"censEu", "censTot", "pCensEu"), class = "data.frame", row.names = c(NA, 
-6L))