DrD的个人博客分享 http://blog.sciencenet.cn/u/DrD

博文

R语言 ggplot2绘制柱状图加误差线

已有 12876 次阅读 2020-7-5 21:28 |个人分类:R语言学习笔记|系统分类:科研笔记| ggplot, 柱状图, 误差线

## 构建数据

dat <- data.frame(var = c("A","B","C"), mean =c (0.25,0.45,0.65), sd = c(0.1,0.15,0.2))

> dat

  var mean   sd

1   A 0.25 0.10

2   B 0.45 0.15

3   C 0.65 0.20

##

library(ggplot2)

f <- ggplot(dat,aes(x=var, y=mean)) +

                   geom_bar(stat = "identity", position=position_dodge(), width=0.6,

                                       color="red", fill=c("white","grey","black")) + ## 柱状图线条颜色和填充色

                   geom_errorbar(aes(ymin=mean-sd, ymax=mean+sd), width=0.2, 

                                            color="blue", ## 误差线颜色

                                            position=position_dodge(0.6))

image.pngimage.png

## 更改主图

f + theme_bw()

image.png



https://wap.sciencenet.cn/blog-3438446-1240730.html

上一篇:R语言 将数据写入到同一个Excel的多个Sheet中
收藏 IP: 211.64.159.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-18 08:36

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部