R语言怎么实现散点图组合频率分布图
发表于:2025-02-04 作者:千家信息网编辑
千家信息网最后更新 2025年02月04日,本篇内容介绍了"R语言怎么实现散点图组合频率分布图"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!首先
千家信息网最后更新 2025年02月04日R语言怎么实现散点图组合频率分布图首先是频率分布直方图
本篇内容介绍了"R语言怎么实现散点图组合频率分布图"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
部分数据如下
做图用到的是最后一列数据
df1<-read.csv("example1.csv",header=T)
library(ggplot2)
ggplot(df1) +
geom_histogram(aes(x = delay,y=..density..),
fill = '#dedede', colour = "black",
binwidth = 1) +
scale_y_continuous("Frequency", expand = c(0,0), limits = c(0,0.20)) +
scale_x_continuous("Delay from onset-to-isolation of infector (days)",
expand = c(0,0),
limits = c(0,27),
breaks = seq(0,27, by = 3)) +
theme_classic() +
theme(#aspect.ratio = 2,
legend.position = 'none')
这里新学到的知识点是theme()
函数里的aspect.ratio
参数,这个参数可以控制整幅图占比,如果是0到1之间就是纵向的压缩,如果是1到2之间就是纵向的压缩,我们分别设置0.5和1.5看下效果
p0.5<-ggplot(df1) +
geom_histogram(aes(x = delay,y=..density..),
fill = '#dedede', colour = "black",
binwidth = 1) +
scale_y_continuous("Frequency", expand = c(0,0), limits = c(0,0.20)) +
scale_x_continuous("Delay from onset-to-isolation of infector (days)",
expand = c(0,0),
limits = c(0,27),
breaks = seq(0,27, by = 3)) +
theme_classic() +
theme(aspect.ratio = 0.5,
legend.position = 'none')
p0.5
p1.5<-ggplot(df1) +
geom_histogram(aes(x = delay,y=..density..),
fill = '#dedede', colour = "black",
binwidth = 1) +
scale_y_continuous("Frequency", expand = c(0,0), limits = c(0,0.20)) +
scale_x_continuous("Delay from onset-to-isolation of infector (days)",
expand = c(0,0),
limits = c(0,27),
breaks = seq(0,27, by = 3)) +
theme_classic() +
theme(aspect.ratio = 1.5,
legend.position = 'none')
cowplot::plot_grid(p0.5,p1.5,labels = c("p0.5","p1.5"))
接下来是散点图散点图的部分数据如下
df2<-read.csv("example2.csv",header=T)
ggplot(df2) +
geom_smooth(method = lm, aes(x=delay, y = n), color = "black", alpha = 0.1, size = 0.7) +
geom_jitter(aes(x = delay, y = n, colour = cluster.risk), height = 0.3, width = 0.3) +
scale_y_continuous("Secondary Cases / Infector", breaks = 1:11) +
scale_x_continuous("Delay from onset-to-confirmation of infector (days)",
expand = c(0,0),
limits = c(0,27), breaks = seq(0,27, by = 3)) +
theme_classic() +
theme(aspect.ratio = 1, legend.position = c(0.85, 0.85), legend.title = element_blank()) #colours are modified custom in post
这里需要注意的是散点图他用到的函数是geom_jitter()
,而没有用geom_point()
,这两个函数的区别是如果两个点的坐标是一样的geom_jitter()
函数也会将两个点分开,而geom_point()
函数会将两个点重叠的画到一起
p1<-ggplot(df1) +
geom_histogram(aes(x = delay,y=..density..),
fill = '#dedede', colour = "black",
binwidth = 1) +
scale_y_continuous("Frequency", expand = c(0,0), limits = c(0,0.20)) +
scale_x_continuous("Delay from onset-to-isolation of infector (days)",
expand = c(0,0),
limits = c(0,27),
breaks = seq(0,27, by = 3)) +
theme_classic() +
theme(#aspect.ratio = 0.5,
legend.position = 'none')
p2<-ggplot(df2) +
geom_smooth(method = lm, aes(x=delay, y = n), color = "black", alpha = 0.1, size = 0.7) +
geom_jitter(aes(x = delay, y = n, colour = cluster.risk), height = 0.3, width = 0.3) +
scale_y_continuous("Secondary Cases / Infector", breaks = 1:11) +
scale_x_continuous("Delay from onset-to-confirmation of infector (days)",
expand = c(0,0),
limits = c(0,27), breaks = seq(0,27, by = 3)) +
theme_classic() +
theme( legend.position = c(0.85, 0.85),
legend.title = element_blank()) #colours are modified custom in post
library(aplot)
p2%>%
insert_top(p1,height = 0.3)
"R语言怎么实现散点图组合频率分布图"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
函数
两个
频率
数据
知识
分布图
语言
组合
接下来
之间
内容
参数
就是
更多
纵向
部分
实用
学有所成
他用
困境
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
access数据库驱动包
学校网络安全主体
介休网络技术团队
okhttp搭建服务器端
sql2000新建数据库
冒险岛台服服务器
数据库按指定字符串截取
先行服务器怎么下载地址
自己搭建服务器成本
汪文斌评美国网络安全360
2021年网络安全漫画图
国家网络安全宣传公益活动
msr数据库
软件开发平台需求
登录苹果id服务器是什么
使用互联网访问自己的电脑服务器
网络安全的复杂性
U盘数据库备份文件怎么打开
edb数据库失败是怎么回事
opc数据存取服务器
管理服务器 导入配置文件
小学网络安全知识图片
服务器哪种性价比最高
自己搭建服务器成本
企业级软件开发框架
湖州app软件开发报价
快速安全的删除手机数据库
网络连接成功却无法连接服务器
网络安全事故 造成的
戴尔服务器raid怎么去掉硬盘