[英]plotting standard errors in R
I have data on the catch rate of certain species of fish. 我有关于某些鱼类捕获率的数据。
fish 1 fish 2 fish 3
0.000 3.265 9.872
2.147 1.013 0.000
I have calculated the mean catch rate for each fish using: 我使用以下方法计算了每条鱼的平均捕获率:
a <- colMeans(df)
I have also calculated the standard error: 我还计算了标准误差:
stdError <- (sapply(df,sd))/sqrt(length(df))
I have created a dotplot using: 我使用以下方法创建了一个dotplot:
dotplot(a, xlab="mean catch", ylab = "species",las =2,)
How do I add error bars to this plot? 如何在此图中添加误差线? I would prefer not to use ggplot if possible.
如果可能的话,我宁愿不使用ggplot。 I am currently using the inbuilt functions in R but have access to Lattice.
我目前正在使用R中的内置函数,但可以访问莱迪思。
Sorry for what is probably a basic question, I am entirely new to plots in R. 对不起可能是一个基本问题,我对R中的情节完全不熟悉。
dotplot
is a lattice function and most default lattice functions don't have great support for confidence intervals. dotplot
是一个晶格函数,大多数默认的晶格函数对置信区间没有很大的支持。 The Hmisc
package extends most lattice functions to better incorporate confidence intervals. Hmisc
包扩展了大多数晶格函数,以更好地结合置信区间。
Here's an example of how you would use it. 这是一个如何使用它的例子。 Note that we combine the data you want to plot here into a data.frame so we can use a proper formula symtax
请注意,我们将您想要绘制的数据组合到data.frame中,以便我们可以使用适当的公式symtax
mm<-data.frame(a,stdError, fish=names(a))
library(lattice)
library(Hmisc)
Dotplot(fish~Cbind(a, a-stdError, a+stdError), mm,
xlab="mean catch", ylab = "species",las =2)
and this produces 这会产生
Note that the Hmisc
version of the function is called Dotplot
while the lattice
version is called dotplot
; 注意,函数的
Hmisc
版本称为Dotplot
而lattice
版本称为dotplot
; capitalization matters. 资本化问题。
Here I've just added/subtracted one standard error from the mean. 在这里,我刚刚从平均值中添加/减去了一个标准误差。 You can calculate the confidence intervals however you like.
您可以随意计算置信区间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.