來源:http://www.practicaldb.com/blog/history-of-data-visualization/
一、名稱怎麼來的
在克裡米亞戰爭期間,南丁格爾發現戰地醫院的衛生條件惡劣導致很多士兵死亡。因此,她開始研究傷員的死亡和衛生環境的關係,並試圖用統計數據說服維多利亞女王改善軍事醫院的衛生條件。但是她也擔心,女王那麼忙,沒有時間看她那厚厚的報告和那些複雜的表格數據。於是,她設計了上面的這個生動又有趣的圖表,巧妙的展示了部隊醫院季節性的死亡率。她自己給它取名叫雞冠花圖(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」四個指標中,又被分別劃成幾個不同的區段
來源:http://thenextweb.com/socialmedia/2010/12/20/facebook-vs-twitter-by-the-numbers-infographic/
2. 披頭四歌曲的音調
來源:http://ritholtz.com/2012/02/the-beatles-song-keys/
3、新冠肺炎全球疫情形勢
三、玫瑰圖怎麼畫
案例1:facebook數據
直接使用上面facebook的數據,關注公眾號AI入門學習回復【facebook】獲取csv文件,用R語言畫個示例,數據格式需要長格式,如下:
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)圖形如下,可以根據個人喜好對顏色進行切換,當然,各種標註,可以在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))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)結果如下:
重新替換一批數據得到下圖
完
推薦閱讀:
刷爆網絡的動態條形圖,3行Python代碼就能搞定
Python初學者必須吃透這69個內置函數!
Python字典詳解-超級完整版
全面理解Python集合,17個方法全解,看完就夠了
長按加群,學習交流
↓掃描關注本號↓