0
我想要創建一個ecdf plot with two lines,我想將errorbars添加到其中的一個。geg_errorbar與ecdf在ggplot
我使用此代碼
x <- c(16,16,16,16,34,35,38,42,45,1,12)
xError <- c(0,1,1,1,3,3,3,4,5,1,1)
y <- c(16,1,12)
length(x)
length(xError)
length(y)
df <- rbind(data.frame(value = x,name='x'),
data.frame(value = y,name='y'))
ggplot(df, aes(x=value,color=name,linetype=name))+ stat_ecdf()+ geom_errorbar(aes(ymax = x + xError, ymin=x - xError))
錯誤條應該加入到x值,但它給我這個錯誤:
Error: Aesthetics must either be length one, or the same length as the dataProblems: x + xError, x - xError
我不明白這一點 - 結果長度相同。
編輯
我改的問題,所以它變得更容易 - 到ECDF圖和誤差條我瘦了真正的問題是相關的。以此代碼爲例:
x <- c(16,16,16,16,34,35,38,42,45,1,12)
xError <- c(0,1,1,1,3,3,3,4,5,1,1)
y <- c(16,1,12)
df <- data.frame(value = x)
ggplot(df, aes(x=value))+ stat_ecdf()+ geom_errorbar(aes(ymax = x + xError, ymin=x - xError))
它打印錯誤欄,但情節已完全中斷。
你想達到什麼不清楚。你想在第一個數據集上有兩個曲線嗎?或者只是名稱爲'x'的曲線? –
@ColonelBeauvel ust曲線名稱x –
我會先計算ecdf,然後將它合併到data.frame,並且只用它繪製'geom_errorbar'。 –