get了Rmisc中的summarySE函数,快速求标准差标准误,便于分析及作图。

我使用的代码:

library(Rmisc)
ymeans <- summarySE(BJp.melt, measurevar="value", groupvars=c("year","type"))

运行效果:

   year type     N        value         sd          se          ci
1  2000    A   507   121.918057  83.597116 0.155100427 0.303992518
2  2000    B   516     1.165986   1.088938 0.002362149 0.004629753
3  2001    A   851    51.867964  37.227834 0.081073688 0.158902421
4  2001    B   488    63.837853  61.232232 0.133148791 0.260968328
5  2002    A   788   129.482674 103.948437 0.237981082 0.466437309

下面是使用说明

Description

Gives count, mean, standard deviation, standard error of the mean, and confidence interval (default 95%).

Usage

summarySE(data = NULL, measurevar, groupvars = NULL,
          na.rm = FALSE, conf.interval = 0.95, .drop = TRUE)

参考链接:

函数更多内容详见:

应用ggplot绘制带误差线的条形图/折线图:
ggplot2-为折线图和条形图添加误差线
Plotting means and error bars (ggplot2)