本文系统介绍ggplot2的统计变换(stat)、位置设置(Position adjustments)和标度(scale)。

本文目录

6、统计变换(stat)stats can be created with a geom_ functionstats can’t be created with a geom_ function7、 位置设置(Position adjustments)条形图中stack|fill|dodge散点图中nudge|jitter|jitterdodge8、标度(scale)marker的形状和大小图例和坐标轴


6、统计变换(stat

将data经过一种统计方法整理,然后再绘图,ggplot2的统计方法如下,都是以stat_开头的函数。

可以分为两类:

stats can be created with a geom_ function

  • stat_bin(): geom_bar(), geom_freqpoly(), geom_histogram()
  • stat_bin2d(): geom_bin2d()
  • stat_bindot(): geom_dotplot()
  • stat_binhex(): geom_hex()
  • stat_boxplot(): geom_boxplot()
  • stat_contour(): geom_contour()
  • stat_quantile(): geom_quantile()
  • stat_smooth(): geom_smooth()
  • stat_sum(): geom_count()
options(repr.plot.width = 4.5, repr.plot.height = 3, repr.plot.res = 300)
f <- ggplot(mpg, aes(class, hwy))
f + geom_boxplot() 

stats can’t be created with a geom_ function

  • stat_ecdf(): compute a empirical cumulative distribution plot.
  • stat_function(): compute y values from a function of x values.
  • stat_summary(): summarise y values at distinct x values.
  • stat_summary2d(), stat_summary_hex(): summarise binned values.
  • stat_qq(): perform calculations for a quantile-quantile plot.
  • stat_spoke(): convert angle and radius to position.
  • stat_unique(): remove duplicated rows.
ggplot(mpg, aes(trans, cty)) + geom_point() + stat_summary(geom = "point", fun = "mean", colour = "red", size = 4)


7、 位置设置(Position adjustments)

  • 条形图中stack|fill|dodge
  • position_stack(): stack overlapping bars (or areas) on top of each other.
  • position_fill(): stack overlapping bars, scaling so the top is always at 1.
  • position_dodge(): place overlapping bars (or boxplots) side-by-side.
options(repr.plot.width = 4.5, repr.plot.height = 5, repr.plot.res = 300)
dplot <- ggplot(diamonds, aes(color, fill = cut)) + xlab(NULL) + ylab(NULL) + theme(legend.position = "none")p1 <- dplot + geom_bar()#默认堆叠
p2 <- dplot + geom_bar(position = "fill")#堆叠且按比例
p3 <- dplot + geom_bar(position = "dodge")#并列p4 <- grid.arrange(p1,p2,p3,nrow = 3)
ggsave("scale23.png", p4, width = 4.5, height = 5) 

  • 散点图中nudge|jitter|jitterdodge
  • position_nudge(): move points by a fixed offset.
  • position_jitter(): add a little random noise to every position.
  • position_jitterdodge(): dodge points within groups, then add a little random noise.
p1 <- ggplot(mpg, aes(displ, hwy)) + geom_point(position = "jitter")
p2 <- ggplot(mpg, aes(displ, hwy)) + geom_point(position = position_jitter(width = 0.05, height = 0.5))
p3 <- ggplot(mpg, aes(displ, hwy)) + geom_jitter(width = 0.05, height = 0.5)p4 <- grid.arrange(p1,p2,p3,nrow = 3)
ggsave("scale24.png", p4, width = 4.5, height = 5) 


8、标度(scale

这部分内容,这里介绍一些没提到的,前面写已过三篇文章详细介绍:

R可视化06|ggplot2图层-标度图层(scale layer)-坐标轴篇
R可视化07|ggplot2图层-标度图层(scale layer)-颜色盘篇
R可视化08|ggplot2图层-标度图层(scale layer)-图例篇

  • marker的形状和大小

使用第一行的数字即可使用第二行的形状。

options(repr.plot.width = 6.5, repr.plot.height = 5, repr.plot.res = 300)#marker形状
p <- e + geom_point(aes(shape = fl, size = cyl))p1 <- p + scale_shape() + scale_size()
p2 <- p + scale_shape_manual(values = c(1:26))#values = c(1:26)指定marker#marker大小
p3 <- p + scale_radius(range = c(1,6))
p4 <- p + scale_size_area(max_size = 6)
p5 <- grid.arrange(p2,p3,p4,nrow = 2)
ggsave("scale25.png", p5, width = 4.5, height = 5)

  • 图例和坐标轴

本文结束,更多好文,欢迎关注公众号:pythonic生物人

Python可视化|Matplotlib39-Matplotlib 1.4W+字教程(珍藏版)
Python可视化|Matplotlib&Seaborn36(完结篇)
python3基础12详解模块和包(库)|构建|使用
Perl基础系列合集
NGS各种组学建库原理(图解)

ggplot2中显示坐标轴_R可视化11|ggplot2-图层图形语法 (3)相关推荐

  1. ggplot2中显示坐标轴_R可视化08|ggplot2图层标度图层(scale layer)图例篇

    "pythonic生物人"的第106篇分享 本文详细介绍ggplot2中图例标度(legends scales),续前篇 R可视化07|ggplot2图层-标度图层(scale l ...

  2. ggplot2中显示坐标轴_qplot()——ggplot2的快速绘图

    先前写过几篇用ggplot2进行基本绘图的文章,但对于初学者,或只需绘制简单图形时,这些命令显得繁琐,这里介绍ggplot2中的快速绘图函数qplot(). 此函数相对能较快速便捷地绘制图形. 往期文 ...

  3. ggplot2中显示坐标轴_ggplot2作图:修改图中一切文本的外观

    参考:<R数据可视化手册> 文本者,ggplot2中的文字也. 包括:1.坐标轴标签 2.标题 3.手动添加文本 4.映射数据的文本等 一.修改坐标轴标签外观: 使用theme(axis. ...

  4. ggplot2设置坐标轴范围_R可视化03|ggplot2图层-几何对象图层(geom layer)

    前面简单介绍ggplot2是基于图层图形语法(the Grammar of Graphics),一张完整图由不同图层叠加而成,本文介绍几何对象图层(geom layer),续前篇: R可视化01|gg ...

  5. 图例符号居中显示_R可视化08|ggplot2图层-标度图层(scale layer)-图例篇

    本文详细介绍ggplot2中图例标度(legends scales),续前篇 R可视化07|ggplot2图层-标度图层(scale layer)-颜色盘篇 本文目录 4.图例标度(legends s ...

  6. Three.js中显示坐标轴、平面、球体、四方体

    场景 Three.js入门和搭建HelloWorld: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/119149625 在上面已 ...

  7. c++ opengl 三维图形中显示文字_为什么使用GPU渲染图形图像,而不使用CPU呢?

    引言 作为程序员,我们或多或少知道可视化应用程序都是由 CPU 和 GPU 协作执行的.那么我们就先来了解一下两者的基本概念: CPU(Central Processing Unit):现代计算机的三 ...

  8. R可视化13|ggplot2-图层图形语法 (5)

    本文系统介绍ggplot2的自带主题(Themes)及主题个性化,续前篇. 本文目录 11.主题(Themes) 自带主题 个性化主题

  9. ggplot2设置坐标轴范围_R语言数据可视化| ggplot2中会“分身术”的facet_wrap()与facet_grid()...

    [R语言]高维数据可视化| ggplot2中会"分身术"的facet_wrap()与facet_grid()姐妹花​mp.weixin.qq.com facet_grid()形成由 ...

最新文章

  1. 受用一生的高效 PyCharm 使用技巧(二)pycharm 指定参数运行文件
  2. 理解JavaScript面向对象的思路
  3. 为什么要选择学Web前端?无法反驳的4大理由
  4. 音视频技术开发周刊 | 188
  5. 算法系列教程04 - 算法相关的基础概念
  6. 木兰编程语言python_ulang(木兰编程语言)
  7. 微信小程序,引爆新热点!JEECG社区小程序实战培训,业内首发,实战干货!
  8. 【快速入眠】高效睡眠 - 把失眠踩在脚下
  9. 实战中的Agile开发
  10. (免费领)Java大厂面试题: 常见的异常类有哪些?
  11. 计算机大赛获奖团队采访,坚持勤奋铸就无悔青春——全国大学生数学建模大赛一等奖获奖者专访...
  12. openwrt折腾记2-广告拦截adbyby与pass
  13. 关于邮箱的正则表达式
  14. 每日学习笔记(21)
  15. 夜深人静了,我们来学学分布式锁
  16. ftp服务器文件不显示,ftp服务器不显示文件夹大小
  17. 官方教你如何为centos 7.x 安装Broadcom无线网卡驱动
  18. 独立思考,提高效率,做更有意义的事
  19. 微信小程序云开发体会——总结软件工程导论大作业
  20. redis—redis概述

热门文章

  1. 人工智能AI Boosting HMC Memory Chip
  2. 用户自定义协议client/server代码示例
  3. 多款激光雷达性能评估
  4. python 判断字符串是否全部为数字组成(使用isdigit)
  5. ArrayAdapter requires the resource ID to be a TextView
  6. com.android.ide.common process ProcessException:Failed to execcue aapt
  7. GridView使用的技巧
  8. 验证插件——jquery.validate.js
  9. 十一运夺金基础数据采集工具
  10. C++负数、小数如何保存