2014-12-04 77 views
0

使用ggplot功能整個數據集的情節,有可能組/顏色感興趣的列並繪製基於該數據,如下所示:如何添加關於GGPLOT2

ggplot(inputDataFrame, aes(as.numeric(interestingColumn) , group = AnotherColumn)) + 
coord_cartesian(xlim = c(0,400)) + geom_line(stat='ecdf') 

我怎麼還可以添加無論「組」標準如何,關於「interestingColumn」中整個數據的曲線/繪圖。這樣我就可以在一個圖中比較整個數據和它的細分組。

例如,運行上面的代碼,我會得到如下圖,我將分別得到每個產品的累計值。無論產品組如何,我都可以在下面的圖表中添加一個圖表,顯示整個產品的消費情況。 enter image description here

謝謝。

+0

對不起,我不明白這個問題。請產生一個[可重現的例子](http://stackoverflow.com/a/5963610/1412059),也許是預期產出的模型。 – Roland 2014-12-04 12:22:40

+0

@羅蘭,抱歉,但現在清楚了嗎?數據非常龐大,我需要從目前無法訪問的中央集羣轉移數據。我想我需要添加這個圖到上面的圖上:ggplot(inputDataFrame,aes(as.numeric(interestingColumn))+ coord_cartesian(xlim = c(0,400))+ geom_line(stat ='ecdf')。 – user30314 2014-12-04 12:38:50

+0

@ user30314,你甚至懶得看鏈接羅蘭張貼? – Henrik 2014-12-04 12:41:09

回答

1

您可以添加沒有顏色美學的geom_line和具有顏色美學的geom_line。另請參閱下面的如何創建可重現的示例。

# create your reproducible example... 
set.seed(1) 
inputDataFrame <- data.frame(interestingColumn = rnorm(100, 200, 80), 
          AnotherColumn = factor(rbinom(100, 4, .3))) 
# plotting 
ggplot(inputDataFrame, aes(as.numeric(interestingColumn))) + 
    coord_cartesian(xlim = c(0,400)) + 
    geom_line(stat='ecdf') + 
    geom_line(aes(color=AnotherColumn), stat='ecdf') 
+0

非常感謝。我遠程工作與我的平板電腦並不能舉一個例子。 – user30314 2014-12-04 13:03:39