2012-03-13 81 views
1

我想使用geom_ribbon來模仿geom_area 的行爲,但我不成功。你會有什麼提示,爲什麼以下不起作用? 我從ggplot2 geom_area web pages使用了Hadley的聲明: 「區域圖是geom_ribbon的特例,其中範圍的最小值固定爲0,位置調整默認爲position_stacked。」堆疊geom_ribbon

test <- expand.grid(Param = LETTERS[1:3], x = 1:5) 
test$y <- test$x 

# Ok 
p <- ggplot(test) 
p <- p + geom_area(aes(x = x, y = y, group = Param, fill = Param), alpha = 0.3) 
p 

# not ok - initial idea 
p <- ggplot(test) 
p <- p + geom_ribbon(aes(x = x, ymin = 0, ymax = y, group = Param, fill = Param), alpha = 0.3, position = position_stack()) 
p 

此外,我怎樣才能看到編碼的方式編碼的方式geom_XXX? 我傳統的方式給出了下面的,這是不是非常有用:

> geom_ribbon 
function (mapping = NULL, data = NULL, stat = "identity", position = "identity", 
    na.rm = FALSE, ...) 
GeomRibbon$new(mapping = mapping, data = data, stat = stat, position = position, 
    na.rm = na.rm, ...) 

感謝您的幫助 問候 帕斯卡爾

回答

2

你只是沒有在你的geom_ribbon調用y一個變量映射。添加y = y使它爲我工作。一般來說,geom_ribbon不需要美學,但我相信它在堆疊的情況下。我相信還有爲什麼這是一個深思熟慮的推理,但你永遠不知道...

此外,所有GGPLOT2的源代碼是關於github