2014-01-08 51 views
0

我認爲這是我如何放置每個aestetic的順序問題。這是相關的代碼。ggplot2 - 區域填充錯誤地繪製區域

enter image description here

有點像正態分佈。將其融化並繪製每個分佈。

df <- as.data.frame(r_data_frame) 
names(df) <- c('Length','Unique','Donor Unique','All') 
library(ggplot2) 
library(reshape2) 
ndf <- melt(df,id.vars='Length') 
print(ndf) 
graph <- ggplot(data=ndf) + geom_area(aes(Length,value,fill=variable)) + 
    theme_bw()+ 
    xlim(1,42)+ 
    geom_hline(yintercept=2369802) + 
    geom_hline(yintercept=2469225,color='red')+ 
    geom_vline(xintercept=15) 

plot(graph) 

this gist

這裏將熔化的數據幀可能是更好的發現是輸出

enter image description here

我遇到的問題是,陰影區域似乎沒有被正確繪製。根據數據框,我繪製了「Donor Unique」和「Unique」的水平線。 「獨一無二」是正確的,因爲它的價值是正確的。然而「捐助者獨特」是高的方式。他們應該勉強重疊。如果你看看世界上發生了什麼事情?我應該使用除geom_area之外的其他東西嗎?

+1

你在'geom_area(...)'中嘗試過'position =「dodge」'嗎? – jlhoward

+0

是的,它把它們放在正確的順序 – jwillis0720

+1

如果您提交作爲答案,我會很樂意接受 – jwillis0720

回答

1

您需要在撥打geom_area(...)時使用position="dodge"

許多geom_*功能ggplot,包括geom_area(...)geom_histogram(...),和geom_bar(...),有一個位置參數。默認值是(通常是...)「堆疊」,這會創建可疊加的幾何圖形。要顯示具有獨立y值的幾何圖形,請使用position =「dodge」。