R可视乎|复合饼图系列

简介: 散点复合饼图(compound scatter and pie chart)可以展示三个数据变量的信息:(x, y, P),其中x和y决定气泡在直角坐标系中的位置,P表示饼图的数据信息,决定饼图中各个类别的占比情况,

散点复合饼图(compound scatter and pie chart)可以展示三个数据变量的信息:(x, y, P),其中x和y决定气泡在直角坐标系中的位置,P表示饼图的数据信息,决定饼图中各个类别的占比情况,如图(a)所示。


气泡复合饼图(compound bubble and pie chart)可以展示四个数据变量的信息:(x, y, z, P),其中x 和y 决定气泡在直角坐标系中的位置,z 决定气泡的大小,P 表示饼图的数据信息,决定饼图中各个类别的占比情况,如图(b)所示。



数据介绍

这是一个和犯罪有关的数据,主要用到里面几列数据,murder、Forcible_rate、Robbery、aggravated_assult、burglary、larceny_theft、motor_vehicle_theft。

library(ggplot2)library(scatterpie)library(RColorBrewer)


crime<- read.csv("~/crimeRatesByState2005.tsv",header = TRUE, sep = "\t", stringsAsFactors = F)radius <- sqrt(crime$population / pi)Max_radius<-max(radius)Bubble_Scale<-0.1crime$radius <- Bubble_Scale * radius/Max_radius


FX4YM9$@2UD3DVQ7V)%~F(T.pngimage.gif


mydata<-crime[,c(2,4,3,5:8)]  #数据集构造Col_Mean<-apply(mydata,2,mean)Col_Sort<-sort(Col_Mean,index.return=TRUE,decreasing = TRUE)mydata<-mydata[,Col_Sort$ix]x<-(mydata$murder-min(mydata$murder))/(max(mydata$murder)-min(mydata$murder))+0.00001y<-(mydata$Robbery-min(mydata$Robbery))/(max(mydata$Robbery)-min(mydata$Robbery))+0.00001


xlabel<-seq(0,10,2)xbreak<-(xlabel-min(mydata$murder))/(max(mydata$murder)-min(mydata$murder))+0.00001ylabel<-seq(0,260,50)ybreak<-(ylabel-min(mydata$Robbery))/(max(mydata$Robbery)-min(mydata$Robbery))+0.00001mydata2<-data.frame(x,y,radius=crime$radius)mydata2<-cbind(mydata2,mydata)Legnd_label<-colnames(mydata2)[4:10]colnames(mydata2)[4:10]<-LETTERS[1:7]


散点复合饼图系列(a)


ggplot() +   geom_scatterpie(aes(x=x, y=y,r=0.05), data=mydata2, cols=colnames(mydata2)[4:10],alpha=0.9,size=0.1) +  scale_fill_manual(values=colorRampPalette(brewer.pal(7, "Set2"))(7),labels=Legnd_label)+  #geom_scatterpie_legend(mydata2$radius, x=0.1, y=0.95, n=5,labeller=function(x) round((x* Max_radius/ Bubble_Scale)^2*pi))+  #geom_scatterpie_legend(mydata2$radius, x=0.009758116, y=0.090868067, n=4,labeller=function(x) round((x* Max_radius/ Bubble_Scale)^2*pi))+  scale_x_continuous(breaks=xbreak, labels=xlabel)+  scale_y_continuous(breaks=ybreak, labels=ylabel)+  xlab("murder")+  ylab("Robbery")+  coord_fixed()+  theme(    axis.title=element_text(size=15,face="plain",color="black"),    axis.text = element_text(size=13,face="plain",color="black"),    legend.title=element_text(size=15,face="plain",color="black"),    legend.text = element_text(size=14,face="plain",color="black"))


TZ70ST{R4I({1$D{$](XZ24.png


散点复合饼图系列(b)

ggplot() +   geom_scatterpie(aes(x=x, y=y,r=radius), data=mydata2, cols=colnames(mydata2)[4:10],alpha=0.9,size=0.25) +  scale_fill_manual(values=colorRampPalette(brewer.pal(7, "Set2"))(7),labels=Legnd_label)+  geom_scatterpie_legend(mydata2$radius, x=0.1, y=0.95, n=5,                         labeller=function(x) round((x* Max_radius/ Bubble_Scale)^2*pi))+  #geom_scatterpie_legend(mydata2$radius, x=0.009758116, y=0.090868067, n=4,labeller=function(x) round((x* Max_radius/ Bubble_Scale)^2*pi))+  scale_x_continuous(breaks=xbreak, labels=xlabel)+  scale_y_continuous(breaks=ybreak, labels=ylabel)+  xlab("murder")+  ylab("Robbery")+  coord_fixed()+  theme(    axis.title=element_text(size=15,face="plain",color="black"),    axis.text = element_text(size=13,face="plain",color="black"),    legend.title=element_text(size=15,face="plain",color="black"),    legend.text = element_text(size=14,face="plain",color="black")  )



W$87XD_)MAA~H$KNL7]03O7.png


目录
相关文章
|
安全 开发工具 git
CTF工具隐写分离神器Binwalk安装和详细使用方法
CTF工具隐写分离神器Binwalk安装和详细使用方法
7611 0
|
Linux 数据安全/隐私保护 iOS开发
CTF—图像隐写三板斧(续)
CTF—图像隐写三板斧(续)
2252 0
|
机器学习/深度学习 JavaScript 前端开发
Mediapipe三维实时人体关键点检测与追踪(一)
Mediapipe三维实时人体关键点检测与追踪(一)
4606 0
|
数据可视化
手把手教你使用 Quarto 构建文档 (2)
手把手教你使用 Quarto 构建文档 (2)
1229 0
|
数据可视化 Serverless
scRNA分析|使用AddModuleScore 和 AUcell进行基因集打分,可视化
scRNA分析|使用AddModuleScore 和 AUcell进行基因集打分,可视化
3615 0
|
SQL API Serverless
Sql之datediff的用法
sql中datediff函数的的用法
3248 0
|
22小时前
|
监控 网络协议 算法
2026年起SSL证书有效期逐年缩短:企业如何避免“续期风暴”!
SSL证书有效期将从2026年起分三阶段逐步缩短至47天,人工续期难以为继。阿里云“WoSign SSL证书+自动化服务”,支持域名监控、自动托管、云产品/服务器一键部署及智能提醒,助力企业高效应对高频续期挑战。
7295 0
|
9天前
|
域名解析 人工智能 Linux
|
20天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
17821 63
|
18天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置

热门文章

最新文章