2013-04-24 41 views
-3

顯示在散點圖的誤差線,所以我也有類似的這種如何,使用R

Value Number 
3 1.5 
6 1.67 
9 1.7 
12 1.6 
15 1.7 
18 1.8 
21 1.9 
24 1.98 
27 1.98 
30 1.8 
33 1.84 
36 1.5 
39 1.7 
42 1.9 
45 1.9 
48 2.0 
51 1.21 
54 1.4 
57 2.34 
60 2.5 
63 2.1 
66 1.77 

如何將使用標準誤差線散點圖數據....我看着它,它似乎去這樣的事情

errbar(df$Value, df$Number, yplus, yminus, cap = 0.015, 
     xlab= deparse(substitute(x)), 
     ylab= deparse(substitute(y))) 

但是我不熟悉yplus,yminus?和deparse? 還有其他方法可以做到這一點嗎?我嘗試使用ggplot和使用install.packages(GGPLOT2)下載,但[R不停地說這不能找到它,並用這個代碼

> ggplot(data=dataset,aes(x=df$Value,y=df$Number,colour=Code,linetype=Group,ymin=Mean-SE,ymax=Mean+SE)) 
Error: could not find function "ggplot" 
> + geom_line() 
Error: could not find function "geom_line" 
> + scale_x_continuous(breaks=c(1,2)) 
Error: could not find function "scale_x_continuous" 
> + scale_linetype_manual(values=c(2,1)) 
Error: could not find function "scale_linetype_manual" 
> + geom_point() 
Error: could not find function "geom_point" 
> + geom_errorbar(width=.1,position='dodge') 
Error: could not find function "geom_errorbar" 

此外,我應該如何去在一個圖形與2個散點圖繪製試了一下x軸的相同值也顯示錯誤欄? 謝謝你們......任何暗示的建議

+0

您是否熟悉''library'? – Roland 2013-04-24 06:48:33

回答

4

你看到的錯誤是因爲ggplot2包尚未加載。將library(ggplot2)添加到腳本將解決此問題。這當然假定安裝了ggplot2包。如果沒有,請使用install.packages("ggplot2")來解決這個問題。

+3

+1幫助和善良 – 2013-04-24 07:26:42

0

或者,你可以使用R的gplots包,這是相當不錯,易於處理(在我看來,至少)。

# Required package 
library(gplots) 

# Sample data 
x <- seq(3, 66, 3) 
y <- c(1.5, 1.67, 1.7, 1.6, 1.7, 1.8, 1.9, 1.98, 1.98, 1.8, 1.84, 
     1.5, 1.7, 1.9, 1.9, 2.0, 1.21, 1.4, 2.34, 2.5, 2.1, 1.77) 
xy <- data.frame(x, y) 

# Plotting 
plotCI(x, y, 
     uiw = .5, gap = 0, pch = 22, pt.bg = "green") 

當然,你必須更換參數uiwliw與誤差向量。

Cheers,Florian