創建華夫餅圖視覺化
方形圓餅圖(又稱華夫餅圖)可用於傳達分類數量的整體部分。要模擬餅圖的百分比視圖,應使用 10x10 網格,每個方格代表總數的 1%。華夫餅圖的現代使用不一定遵守此規則,可以使用任何矩形形狀的網格來建立。最佳實踐建議保持較小的類別數量,就像創建餅圖時應該做的那樣。提供了工具來創建華夫餅圖並將它們縫合在一起,並使用字形來製作同型象形圖。
它使用 ggplot2 並傳回 ggplot2 物件。
實現了以下功能:
waffle
:製作華夫餅(方形餅圖)圖表
draw_key_pictogram
:象形圖的圖例產生器
fa_grep
:搜尋模式的 Font Awesome 字形名稱
fa_list
:列出所有 Font Awesome 字形
fa5_brand
: Font Awesome 5 品牌
fa5_solid
: Font Awesome 5 固體
geom_pictogram
: 象形圖 Geom
geom_waffle
: 華夫餅(方形餅圖)Geom
install_fa_fonts
: 安裝 Font Awesome 5 字型
iron
:華夫餅圖的垂直左對齊佈局
scale_label_pictogram
:與 geom_pictogram() 一起使用將 Font Awesome 字體對應到標籤
theme_enhance_waffle
:華夫餅圖主題污垢去除器,可與任何其他主題一起使用
install.packages( " waffle " ) # NOTE: CRAN version is 0.7.0
# or
remotes :: install_github( " hrbrmstr/waffle " )
注意:要使用「remotes」安裝選項,您需要安裝 {remotes} 軟體包。
library( waffle )
library( magrittr )
library( hrbrthemes )
library( ggplot2 )
library( dplyr )
library( waffle )
# current verison
packageVersion( " waffle " )
# # [1] '1.0.2'
data.frame (
parts = factor (rep( month.abb [ 1 : 3 ], 3 ), levels = month.abb [ 1 : 3 ]),
vals = c( 10 , 20 , 30 , 6 , 14 , 40 , 30 , 20 , 10 ),
col = rep(c( " navy " , " black " , " maroon " ), 3 ),
fct = c(
rep( " Thing 1 " , 3 ),
rep( " Thing 2 " , 3 ),
rep( " Thing 3 " , 3 )
)
) - > xdf
xdf % > %
count( parts , wt = vals ) % > %
ggplot(
aes( fill = parts , values = n )
) +
geom_waffle(
n_rows = 20 ,
size = 0.33 ,
colour = " white " ,
flip = TRUE
) +
scale_fill_manual(
name = NULL ,
values = c( " #a40000 " , " #c68958 " , " #ae6056 " ),
labels = c( " Fruit " , " Sammich " , " Pizza " )
) +
coord_equal() +
theme_ipsum_rc( grid = " " ) +
theme_enhance_waffle()
xdf % > %
count( parts , wt = vals ) % > %
ggplot(
aes( label = parts , values = n )
) +
geom_pictogram(
n_rows = 10 ,
aes( colour = parts ),
flip = TRUE ,
make_proportional = TRUE
) +
scale_color_manual(
name = NULL ,
values = c( " #a40000 " , " #c68958 " , " #ae6056 " ),
labels = c( " Fruit " , " Sammich " , " Pizza " )
) +
scale_label_pictogram(
name = NULL ,
values = c( " apple-alt " , " bread-slice " , " pizza-slice " ),
labels = c( " Fruit " , " Sammich " , " Pizza " )
) +
coord_equal() +
theme_ipsum_rc( grid = " " ) +
theme_enhance_waffle() +
theme(
legend.key.height = unit( 2.25 , " line " ),
legend.text = element_text( size = 10 , hjust = 0 , vjust = 0.75 )
)
xdf % > %
count( parts , wt = vals ) % > %
ggplot(
aes( label = parts , values = n )
) +
geom_pictogram(
n_rows = 20 ,
size = 6 ,
aes( colour = parts ),
flip = TRUE ,
family = " FontAwesome5Brands-Regular "
) +
scale_color_manual(
name = NULL ,
values = c( " #073f9c " , " black " , " #f34323 " ),
labels = c( " BitBucket " , " GitHub " , " Other " )
) +
scale_label_pictogram(
name = NULL ,
values = c( " bitbucket " , " github " , " git-alt " ),
labels = c( " BitBucket " , " GitHub " , " Other " )
) +
coord_equal() +
theme_ipsum_rc( grid = " " ) +
theme_enhance_waffle() +
theme(
legend.text = element_text( hjust = 0 , vjust = 1 )
)
library( hrbrthemes )
library( waffle )
library( tidyverse )
tibble(
parts = factor (rep( month.abb [ 1 : 3 ], 3 ), levels = month.abb [ 1 : 3 ]),
values = c( 10 , 20 , 30 , 6 , 14 , 40 , 30 , 20 , 10 ),
fct = c(rep( " Thing 1 " , 3 ), rep( " Thing 2 " , 3 ), rep( " Thing 3 " , 3 ))
) - > xdf
ggplot(
data = xdf ,
aes( fill = parts , values = values )
) +
geom_waffle(
color = " white " ,
size = 1.125 ,
n_rows = 6
) +
facet_wrap( ~ fct , ncol = 1 ) +
scale_x_discrete(
expand = c( 0 , 0 , 0 , 0 )
) +
scale_y_discrete(
expand = c( 0 , 0 , 0 , 0 )
) +
ggthemes :: scale_fill_tableau( name = NULL ) +
coord_equal() +
labs(
title = " Faceted Waffle Geoms "
) +
theme_ipsum_rc( grid = " " ) +
theme_enhance_waffle()
library( dplyr )
library( waffle )
storms % > %
filter( year > = 2010 ) % > %
count( year , status ) - > storms_df
ggplot(
data = storms_df ,
aes( fill = status , values = n )
) +
geom_waffle(
color = " white " ,
size = .25 ,
n_rows = 10 ,
flip = TRUE
) +
facet_wrap(
~ year ,
nrow = 1 ,
strip.position = " bottom "
) +
scale_x_discrete() +
scale_y_continuous(
labels = function ( x ) x * 10 , # make this multiplier the same as n_rows
expand = c( 0 , 0 )
) +
ggthemes :: scale_fill_tableau( name = NULL ) +
coord_equal() +
labs(
x = " Year " , y = " Count " ,
title = " Faceted Waffle Bar Chart " ,
subtitle = " {dplyr} storms data "
) +
theme_minimal(
base_family = " Roboto Condensed "
) +
theme(
panel.grid = element_blank(),
axis.ticks.y = element_line()
) +
guides(
fill = guide_legend( reverse = TRUE )
)
parts <- c( 80 , 30 , 20 , 10 )
waffle( parts , rows = 8 )
parts <- data.frame (
names = LETTERS [ 1 : 4 ],
vals = c( 80 , 30 , 20 , 10 )
)
waffle( parts , rows = 8 )
c(
`Un-breachednUS Population` = ( 318 - 11 - 79 ),
`Premera` = 11 ,
`Anthem` = 79
) - > parts
waffle(
parts = parts ,
rows = 8 ,
size = 1 ,
colors = c( " #969696 " , " #1879bf " , " #009bda " ),
legend_pos = " bottom "
)
健康記錄洩漏占美國人口的比例
一平方 == 1m 人
waffle(
parts = parts / 10 ,
rows = 3 ,
colors = c( " #969696 " , " #1879bf " , " #009bda " )
)
健康記錄洩漏占美國人口的比例
(一平方 == 10m 人)
library( extrafont )
waffle(
parts = parts / 10 ,
rows = 3 ,
colors = c( " #969696 " , " #1879bf " , " #009bda " ),
use_glyph = " medkit " ,
size = 8
) +
expand_limits(
y = c( 0 , 4 )
)
資料來源:https://www.nytimes.com/2008/07/20/business/20debt.html
c(
`Mortgagen($84,911)` = 84911 ,
`Auto andntuition loansn($14,414)` = 14414 ,
`Home equity loansn($10,062)` = 10062 ,
`Credit Cardsn($8,565)` = 8565
) - > savings
waffle(
parts = savings / 392 ,
rows = 7 ,
size = 0.5 ,
legend_pos = " bottom " ,
colors = c( " #c7d4b6 " , " #a3aabd " , " #a0d0de " , " #97b5cf " )
)
每年平均家庭儲蓄
(1 平方 == 392 美元)
類似 https://eagereyes.org/techniques/square-pie-charts
professional <- c( `Male` = 44 , `Female (56%)` = 56 )
waffle(
parts = professional ,
rows = 10 ,
size = 0.5 ,
colors = c( " #af9139 " , " #544616 " )
)
和:
iron(
waffle(
parts = c( thing1 = 0 , thing2 = 100 ),
rows = 5
),
waffle(
parts = c( thing1 = 25 , thing2 = 75 ),
rows = 5
)
)
沒有(您現在可以透過keep
參數停用它):
iron(
waffle(
parts = c( thing1 = 0 , thing2 = 100 ),
rows = 5 ,
keep = FALSE
),
waffle(
parts = c( thing1 = 25 , thing2 = 75 ),
rows = 5 ,
keep = FALSE
)
)
專業勞動力彩妝
Iron 範例(多個圖表的左對齊和填充)
pain.adult.1997 <- c( `YOY (406)` = 406 , `Adult (24)` = 24 )
waffle(
parts = pain.adult.1997 / 2 ,
rows = 7 ,
size = 0.5 ,
colors = c( " #c7d4b6 " , " #a3aabd " ),
title = " Paine Run Brook Trout Abundance (1997) " ,
xlab = " 1 square = 2 fish " , pad = 3
) - > A
pine.adult.1997 <- c( `YOY (221)` = 221 , `Adult (143)` = 143 )
waffle(
parts = pine.adult.1997 / 2 ,
rows = 7 ,
size = 0.5 ,
colors = c( " #c7d4b6 " , " #a3aabd " ),
title = " Piney River Brook Trout Abundance (1997) " ,
xlab = " 1 square = 2 fish " , pad = 8
) - > B
stan.adult.1997 <- c( `YOY (270)` = 270 , `Adult (197)` = 197 )
waffle(
parts = stan.adult.1997 / 2 ,
rows = 7 ,
size = 0.5 ,
colors = c( " #c7d4b6 " , " #a3aabd " ),
title = " Staunton River Trout Abundance (1997) " ,
xlab = " 1 square = 2 fish "
) - > C
iron( A , B , C )
cloc :: cloc_pkg_md()
郎 | # 文件 | (%) | 控制點 | (%) | 空行 | (%) | # 行 | (%) |
---|---|---|---|---|---|---|---|---|
右 | 14 | 0.44 | 624 | 0.35 | 218 | 0.36 | 第439章 | 0.38 |
平均數 | 2 | 0.06 | 255 | 0.15 | 88 | 0.14 | 139 | 0.12 |
和 | 16 | 0.50 | 第879章 | 0.50 | 306 | 0.50 | 第578章 | 0.50 |
{克洛克}?華夫餅的指標
請注意,該項目是隨貢獻者行為準則一起發布的。參與該項目即表示您同意遵守其條款。