来源:AI入门学习
作者:伍正祥
在克里米亚战争期间,南丁格尔发现战地医院的卫生条件恶劣导致很多士兵死亡。因此,她开始研究伤员的死亡和卫生环境的关系,并试图用统计数据说服维多利亚女王改善军事医院的卫生条件。但是她也担心,女王那么忙,没有时间看她那厚厚的报告和那些复杂的表格数据。于是,她设计了上面的这个生动又有趣的图表,巧妙的展示了部队医院季节性的死亡率。她自己给它取名叫鸡冠花图(coxcomb)。
我们先来看看最早的南丁格尔玫瑰图展示了什么样的数据。这张图展示的是1854年4月到1855年3月这一年间士兵的死亡情况。其中:
1)绿色表示死于可预防疾病的士兵人数;
2)红色表示死于枪伤的人数;
3)黑色表示死于其他意外的人数。
从图中可以看出,在这一年间,死亡人数最多的并不是在战争中受枪伤(红色部分),大部分的士兵是死于可预防疾病(绿色部分),特别是冬天的时候(1854年11月-1855年2月),死于可预防疾病的士兵人数大幅增加。这也反映出医院的卫生条件、保暖对于伤员的康复是多么的重要。因此,才说服了女王大人改善医院条件。
这么有气质的图表,我们来看看经过这么多年的发展,大家都是怎么用的。尽管外形很像饼图,但本质上来说,南丁格尔玫瑰图更像在极坐标下绘制的柱状图或堆叠柱状图。只不过,它用半径来反映数值(而饼图是以扇形的弧度来表示数据的)。但是,由于半径和面积之间是平方的关系,视觉上,南丁格尔玫瑰图会将数据的比例夸大。因此,当我们追求数据的准确性时,玫瑰图不一定是个好的选择。但反过来说,当我们需要对比非常相近的数值时,适当的夸大会有助于分辨。
1. Facebook 和 twitter的用户对比
1)图表中包括性别、年龄、教育、收入等11个分类的对比信息指标,每个指标占用的圆周的角度相同,即任一指标的扇区角度为(360/11=32.723度)。
2)在“Gender”,“Income”,“Age”,“Education”四个指标中,又被分别划成几个不同的区段。
2、新冠肺炎全球疫情形势
案例1:facebook数据
直接使用上面facebook的数据,关注公众号AI入门学习回复【facebook】获取csv文件,用R语言画个示例,数据格式需要长格式,如下:
#facebooks数据 library(ggplot2) facebook = read.csv("facebook.csv",header=T,stringsAsFactors = FALSE) ggplot(facebook, aes(x = 类别1,y=比例,fill = 类别2)) + geom_bar(alpha = 0.93,stat="identity") + coord_polar()+ theme_bw()+ theme(panel.background = element_rect(fill = "black"))+ theme(axis.text = element_blank())+ theme(axis.ticks = element_blank())+# 去掉左上角的刻度线 theme(axis.title = element_blank())+ theme(legend.position = 'none')+# 去掉图例 theme(panel.border = element_blank())+# 去掉外层边框
theme(panel.background = element_rect(fill = "black"))+ #黑色背景 theme(panel.grid.major.x = element_line(colour =
"SpringGreen2", size = 0.3))+ #网格线设置 theme(panel.grid.major.y =
element_line(colour = "SpringGreen2", size = 0.3))+ #网格线设置 ylim(-0.3,1.1)+ scale_fill_discrete(c=1000, l=100) ggsave('rose.png',dpi = 1080)#保存为高清格式,dpi越大越清晰
图形如下,可以根据个人喜好对颜色进行切换,当然,各种标注,可以在PPT中完成,多个对比的,也可以在PPT中进行拼接。
用R自带数据集画一个不带网格线的
dsmall = diamonds[sample(nrow(diamonds),5000),] ggplot(dsmall, aes(x = clarity, fill = cut)) + geom_bar(alpha = 0.85) + coord_polar() + theme_bw() + theme(panel.background = element_rect(fill = "black"))+ theme(axis.text = element_blank())+ theme(axis.ticks = element_blank())+# 去掉左上角的刻度线 theme(axis.title = element_blank())+ theme(legend.position = 'none')+# 去掉图例 theme(panel.border = element_blank())+# 去掉外层边框
theme(panel.background = element_rect(fill = "black"))+ #黑色背景 theme(panel.grid=element_blank())+ ylim(-50,1000)+ scale_fill_manual(values = alpha(c("DarkOrchid1", "SpringGreen", "Magenta","Cyan","OrangeRed1"))) ggsave('rose.png',dpi = 1080)
案例2:多图组合
首先,介绍个函数,多个图组合到一起的
multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) { library(grid) plots <- c(list(...), plotlist) numPlots = length(plots) if (is.null(layout)) { layout <- matrix(seq(1, cols * ceiling(numPlots/cols)), ncol = cols, nrow = ceiling(numPlots/cols)) } if (numPlots==1) { print(plots[[1]]) } else { grid.newpage() pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout)))) for (i in 1:numPlots) { matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE)) print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row, layout.pos.col = matchidx$col)) } } }
开始绘图部分,下六组数据替换分别跑一次,得到 p1,p2,p3,p4,p5,p6,然后用上面定义的函数组合即可
par(mar=c(0,0,0,0)) #c(4,3,8,2,2,1) #c(4,3,5,2,2,10) #c(15,3,5,8,2,8) #c(1,3,5,3,2,8)
#c(1,3,9,3,2,3) #c(2,12,9,3,2,3) data = data.frame(value= c(2,12,9,3,2,3), type = c('B','A','C','D','E',F)) p1 = ggplot(data, aes(x =type, y=value, fill=type)) + geom_bar(stat = "identity", alpha = 0.99) + coord_polar() + theme_bw() + theme(panel.background = element_rect(fill = "black"))+ theme(axis.text = element_blank())+ theme(axis.ticks = element_blank())+# 去掉左上角的刻度线 theme(axis.title = element_blank())+ theme(legend.position = 'none')+# 去掉图例 theme(panel.border = element_blank())+# 去掉外层边框 theme(panel.background =
element_rect(fill = "black"))+ #黑色背景 theme(panel.grid=element_blank())+ scale_fill_manual(values = alpha(c("OrangeRed1", 'gray91',"SpringGreen", "Magenta","Cyan", "DarkOrchid1"))) multiplot(p1,p2,p3,p4,p5,p6,cols=3)
结果如下:
重新替换一批数据得到下图
数据分析咨询请扫描二维码
数据挖掘是现代企业利用数据驱动决策的重要工具。它涉及从大量数据中提取隐藏的、先前未知但潜在有用的信息,依托人工智能、机器 ...
2024-10-23在当前数据驱动的商业环境中,数据分析师的角色变得越来越重要。想要踏入这一领域并取得成功,不仅需要扎实的技术基础,还需要不 ...
2024-10-23数据分析是一个广泛而又精细的领域,它结合了统计学、计算机科学、商业策略以及数据科学等多个学科的知识。这个领域日新月异的发 ...
2024-10-23在现代企业中,数字化管理师扮演着至关重要的角色。他们不仅帮助企业优化资源配置,还推动企业的数字化转型。要成为一名合格的数 ...
2024-10-23大数据专业是一个跨学科的领域,涵盖了数学、统计学、计算机科学与技术等多个学科。随着数据在各个行业中的重要性日益增加,大数 ...
2024-10-23大数据分析师培训教程-2.1 Hadoop入门-Hadoop 1.0 的局限与 Hadoop 2.0(YARN)的革新 Hadoop简介Hadoop 的生态系统HDFS 的原理 ...
2024-10-232024,您是否渴望在数据领域探索更广阔的职业机遇? 数字化时代,数据量级每年都在呈指数级增长。据统计,全球互联网用户每天产 ...
2024-10-21数据科学专业是一门跨学科的综合性学科,涵盖了数学、统计学、计算机科学等多个领域。其核心目标是通过数据的收集、处理和分析来 ...
2024-10-21Python是一种高级解释性编程语言,由Guido van Rossum于1991年创造。凭借其简单易学、代码可读性强和功能强大的特点,Python已经 ...
2024-10-21在当今数据驱动的世界中,选择学习Hadoop已成为许多数据分析师和IT专业人士的必修课。Hadoop不仅是大数据处理领域的核心技术之一 ...
2024-10-21数据开发工程师在当今数据驱动的世界中扮演着至关重要的角色。他们不仅负责数据的采集和处理,还在数据仓库建设、系统开发和数据 ...
2024-10-20在当今快速变化的数字经济时代,数字化转型已经成为企业实现持续增长和竞争优势的关键。数字化转型不仅仅是技术的变革,更是组织 ...
2024-10-19在当今快速发展的科技时代,数字经济已成为全球经济的重要组成部分。选择数字经济专业,不仅能为你打开通往多个行业的大门,还能 ...
2024-10-18学习统计学与大数据分析具有显著的优势,能够帮助你走向高薪岗位。在数字化时代背景下,统计学和大数据分析展现出强大的就业潜力 ...
2024-10-18在当今的数字时代,数据科学与大数据技术专业的就业方向极为广泛,涵盖了多个领域和岗位。随着数据成为企业决策的重要依据,行业 ...
2024-10-18大数据技术与应用领域正在迅速发展,成为现代经济和科技发展的重要驱动力。随着数据量的爆炸式增长,各行各业对大数据专业人才的 ...
2024-10-18在当今数据驱动的商业环境中,数据分析软件已成为企业决策过程中不可或缺的工具。随着数据量的激增和分析需求的复杂化,选择合适 ...
2024-10-18在当今数据驱动的世界中,数据分析已成为许多行业不可或缺的一部分。无论是企业决策、市场营销,还是产品开发,数据分析都能提 ...
2024-10-18数据分析在现代企业中扮演着至关重要的角色,帮助企业在竞争激烈的市场中做出明智的决策。随着数据量的不断增长,企业需要依赖先 ...
2024-10-18CDA(Certified Data Analyst)认证在数据分析领域具有显著的作用,具体包括以下几个方面: 1. 专业技能认可 CDA认证是数据分析 ...
2024-10-17