ggplot绘制带误差线的柱状图

  1. 利用ggplot2
  2. 数据格式转换并做统计计算
  3. 绘制图形
## 模拟
## 导入包
library(ggplot2)
library(reshape2)
library(RColorBrewer)## 载入数据
df <- iris
df <- melt(df, id="Species", variable.name="Attribute", value.name = "Size")
mycol= brewer.pal(n = 12, name = "Set3")## 统计 3种鸢尾花形态数据数据均值、标准差、标准误
mean <- aggregate(df$Size, by=list(df$Species, df$Attribute), FUN=mean)
sd <- aggregate(df$Size, by=list(df$Species, df$Attribute), FUN=sd)
len <- aggregate(df$Size, by=list(df$Species, df$Attribute), FUN=length)
df_res <- data.frame(mean, sd=sd$x, len=len$x)
colnames(df_res) = c("Species", "Attribute", "Mean", "Sd", "Count")
str(df_res)
df_res$Se <- df_res$Sd/sqrt(df_res$Count) ### 计算标准差### ggplot 绘图 (标准差:误差线)
ggplot(df_res, aes(x=Attribute, y=Mean, fill=Species)) +geom_bar(stat="identity", position=position_dodge(),color="black", width=.6) +scale_fill_manual(values = mycol) +geom_errorbar(aes(ymin=Mean-Sd, ymax=Mean +Sd),position=position_dodge(.6), width=.2)theme_bw()ggplot(df_res, aes(x=Attribute, y=Mean, fill=Species)) +geom_bar(stat="identity", position=position_dodge(),color="black", width=.6) +scale_fill_manual(values = mycol) +geom_errorbar(aes(ymin=Mean-Sd, ymax=Mean +Sd),position=position_dodge(.6), width=.2) +theme_bw()

R - ggplot绘制带误差线的柱状图相关推荐

  1. Matlab绘制带误差线的柱状图

    Matlab可绘制带误差线的柱状图(需下载barweb (BARgraph With Error Bars) - File Exchange - MATLAB Central并设置路径),成图如下所示 ...

  2. R语言绘制带误差线的条形图

    条形统计图是用一个单位长度表示一定的数量,根据数量的多少画成长短不同的直条.带误差的条形图可以通过误差线来判断显著性. 继续使用我们的汽车销售数据(公众号回复:汽车销售,可以获得该数据)来演示,先导入 ...

  3. Python+Matplotlib绘制带误差线的柱状图

    推荐图书: <Python程序设计(第3版)>,(ISBN:978-7-302-55083-9),董付国,清华大学出版社,2020年6月第1次印刷,2021年12月第11次印刷,山东省一流 ...

  4. matlab 条形图误差线,数据可视化系列:手把手教你绘制带误差线的条形图

    原标题:数据可视化系列:手把手教你绘制带误差线的条形图 条形图可以用于展示数据不同分类下的均值.中位数.标准差和置信区间等,Excel可以实现,但对于带误差线的条形图而言,还是比较麻烦的.R语言的基础 ...

  5. python-科研绘图系列(1)-带误差线的柱状图

    1.带误差线的柱状图 import numpy as np import pandas as pd import matplotlib.pyplot as pltfig=plt.figure(figs ...

  6. 绘制带有误差线的柱状图

    绘制带有误差线的柱状图,代码比较简单就不再解释了 # a stacked bar plot with errorbars import numpy as np import matplotlib.py ...

  7. Python绘制带误差线的图形 Python plots with error bands

    If you want to plot a function curve with multiple parameters with errors, one way to visualize the ...

  8. python绘制带误差线的条形图

    绘制格式: plt.bar(index, values, yerr = std, error_kw = {'ecolor' : '0.2', 'capsize' :6}, alpha=0.7) yer ...

  9. 3.3带误差线的柱状图

最新文章

  1. oracle 11g完全安装教程(CentOS)
  2. 凯撒密码、GDP格式化输出、99乘法表
  3. 关于登录记住密码使用cookie的详解
  4. 字典怎么增加元素_python3基础之字典
  5. Windows原生运行Linux的技术细节
  6. Js中substr,substring,slice截取字符串的异同
  7. 内部排序——直接插入排序
  8. mysql知识总结体会博客_可能是全网最好的MySQL重要知识点/面试题总结||CSDN博客精选...
  9. centos下添加的端口不能访问(防火墙关闭)
  10. html+not选择器,CSS3属性选择器与(:not)选择器_html/css_WEB-ITnose
  11. 【pmcaff1220】三个案例教你如何玩转跨界
  12. SAP ABAP实用技巧介绍系列之 在xslt里call ABAP method
  13. sql分割函数|在网上找的看着挺好,谁的忘了
  14. #6282. 数列分块入门 6
  15. 鼠标右键快速连接wifi
  16. WebService与RestAPI 、SoapAPI
  17. linux时间戳转换c语言,C语言将时间戳转换成日期时间
  18. 完整的连接器设计手册_连接器退化机理是什么?(一)
  19. 在linux系统中使用shc指令,Linux编译安装SHC加密组件
  20. PHP 接入微信公众账号API

热门文章

  1. jenkins日志乱码linux,jenkins中文及符号乱码
  2. 【移动测试Android】元素定位|基本操作|手势操作
  3. 播放PPT时,如何可以在学员面前不显示备注呢?
  4. 信息论与编码习题(一)
  5. gym101522 [小熊骑士限定]La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017...
  6. [斜率优化] 斜率优化学习笔记
  7. MIMIC数据库官方SQL查询标注和初步分析--sofa评分(2-19)
  8. Android端的移动支付-银联支付
  9. matlab的数值求解实验报告,matlab计算方法实验报告5(数值积分)
  10. useState 函数式状态管理