2016-06-23 18 views
1

私はggplot2geom_areaでプロットをしようとしています。塗りは変数で設定します。何らかの理由で、「外側」グループだけが満たされます。私は、内側の領域も充満させる方法を理解できません。ggplot geom_areaの未塗装領域

同じ問題が発生するようですが、here解決方法はありません。私は任意の助けが理解されるであろう

R 3.3およびggplot2_2.1.0を使用してい

and the resulting plot

以下は私が使用しているコードと、得られたプロットの最小の例です。

df <- data.frame(month = seq(from = as.Date("2016-01-01"), to = as.Date("2016-12-31"), by = "month"), 
      type = c(rep("past", times = 5), "current", rep("future", times = 6)), 
      amount = c(seq(from = 100, to = 1200, by = 100))) 

df$type <- factor(df$type, levels = c("past", "current", "future")) 


ggplot(data = df, aes(x = month, y = amount, fill = type)) + 
    geom_area() 
+0

理由は 'current'は一度だけ発生することです。だからあなたにはエリアがありません。 – Alex

+1

geom_bar(stat = 'identity') ' – Jaap

+0

' ggplot(data = df、aes(x =月、y =量、塗りつぶし=タイプ))+ geom_bar(stat = "identity") ' – Alex

答えて

0

領域を生成するために、現在の値に2ポイントの時間を追加しました。問題は、1つのポイントでは領域を描画できないことです。

library(ggplot2) 

df <- data.frame(month = seq(from = as.Date("2016-01-01"), to = as.Date("2016-12-31"), by = "month"), 
       type = c(rep("past", times = 5), "current", rep("future", times = 6)), 
       amount = c(seq(from = 100, to = 1200, by = 100))) 

df <- rbind(df[1:5, ], 
      data.frame(month = as.Date(c("2016-05-15", "2016-06-15")), 
         type = c("current", "current"), 
         amount = c(550, 650)), 
      df[7:12, ]) 

df$type <- factor(df$type, levels = c("past", "current", "future")) 


ggplot(data = df, aes(x = month, y = amount, fill = type)) + 
geom_area() 

enter image description here

+0

あなたの答えAlexに感謝します。これは実際に塗りつぶしの問題を解決します。しかし、あなたの答えと上記のコメントを読んだ後、私は別のルートに行くことを決めました(上記のコメントを参照)。 – thoring

関連する問題