ggplot2 geom函数第一讲geom_abline、geom_hline、geom_bar和geom_col

参考https://ggplot2.tidyverse.org/reference/

1.geom_abline和geom_hline

ggplot(mtcars) +
  geom_point(aes(mpg, disp, colour = gear)) +
  theme_bw()+
  geom_hline(yintercept = c(300, 400), colour = 'red', linetype = 2, size = 2) +
  geom_vline(xintercept = c(20, 25), colour = 'blue', linetype = 3, size = 3)
image.png

2.geom_bar和geom_col

2.1 count or weight 数量或权重

g <- ggplot(mpg, aes(class))
g + geom_bar() #count
g + geom_bar(aes(weight = displ)) #weight
count
weight

2.2 方向,把数据赋值给y,则转为横向

ggplot(mpg) + geom_bar(aes(y = class))
横向

2.3 position

p <- ggplot(data = diamonds, mapping = aes(x = cut, fill = clarity))

#default position stack
p + geom_bar() 

#identity由于遮挡问题不适合做bar图
p + geom_bar(position = "identity") 

p + geom_bar(position = "identity", fill = NA, aes(colour = clarity))

p + geom_bar(position = "fill")

p + geom_bar(position = "dodge")
stack
identity
identity透明
fill
dodge
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • !备忘,方便自己查询,随着使用更新,无参考价值。 Function reference[https://ggplo...
    shwzhao阅读 4,680评论 0 7
  • 作者:严涛浙江大学作物遗传育种在读研究生(生物信息学方向)伪码农,R语言爱好者,爱开源 ggplot2学习笔记之图...
    Dylan的迪阅读 7,648评论 0 6
  • 第一部分 探索 第1章 使用ggplot2进行数据可视化 1.1 简介 首先安装并加载R包(ggplot2) 我们...
    亚航阅读 9,675评论 0 7
  • 写在前面 ggplot2 是一个功能强大且灵活的R包 ,由Hadley Wickham 编写,其用于生成优雅的图...
    Boer223阅读 28,435评论 0 67
  • 简介 文章较长,点击直达我的博客,浏览效果更好。本文内容基本是来源于STHDA,这是一份十分详细的ggplot2使...
    taoyan阅读 51,565评论 7 159