Buat Visualisasi Bagan Wafel
Diagram lingkaran persegi (alias diagram wafel) dapat digunakan untuk mengkomunikasikan bagian dari keseluruhan untuk kuantitas kategorikal. Untuk meniru tampilan persentase diagram lingkaran, grid 10x10 harus digunakan dengan masing-masing kotak mewakili 1% dari total. Penggunaan diagram wafel modern tidak selalu mengikuti aturan ini dan dapat dibuat dengan kisi-kisi berbentuk persegi panjang apa pun. Praktik terbaik menyarankan agar jumlah kategori tetap kecil, seperti yang harus dilakukan saat membuat diagram lingkaran. Alat disediakan untuk membuat bagan wafel serta menyatukannya, dan menggunakan mesin terbang untuk membuat piktogram isotipe.
Ia menggunakan ggplot2 dan mengembalikan objek ggplot2.
Fungsi-fungsi berikut diterapkan:
waffle
: Membuat bagan wafel (kue persegi).
draw_key_pictogram
: Pembuat legenda untuk piktogram
fa_grep
: Cari Font Nama mesin terbang yang mengagumkan untuk suatu pola
fa_list
: Daftar semua mesin terbang Font Awesome
fa5_brand
: Font Luar Biasa 5 Merek
fa5_solid
: Font Luar Biasa 5 Padat
geom_pictogram
: Piktogram Geom
geom_waffle
: Wafel (Bagan lingkaran persegi) Geom
install_fa_fonts
: Instal Font Awesome 5 Font
iron
: Tata letak vertikal dan rata kiri untuk plot wafel
scale_label_pictogram
: Digunakan dengan geom_pictogram() untuk memetakan font Font Awesome ke label
theme_enhance_waffle
: Penghilang kerak tema bagan wafel yang dapat digunakan dengan tema lainnya
install.packages( " waffle " ) # NOTE: CRAN version is 0.7.0
# or
remotes :: install_github( " hrbrmstr/waffle " )
CATATAN: Untuk menggunakan opsi instalasi 'remotes' Anda perlu menginstal paket {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 "
)
Pelanggaran catatan kesehatan sebagian kecil dari Populasi AS
Satu persegi == 1m ppl
waffle(
parts = parts / 10 ,
rows = 3 ,
colors = c( " #969696 " , " #1879bf " , " #009bda " )
)
Pelanggaran catatan kesehatan sebagian kecil dari Populasi AS
(Satu persegi == 10m ppl)
library( extrafont )
waffle(
parts = parts / 10 ,
rows = 3 ,
colors = c( " #969696 " , " #1879bf " , " #009bda " ),
use_glyph = " medkit " ,
size = 8
) +
expand_limits(
y = c( 0 , 4 )
)
Melalui: 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 " )
)
Rata-rata Tabungan Rumah Tangga Setiap Tahun
(1 kotak == $392)
Mirip dengan 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 " )
)
Dengan:
iron(
waffle(
parts = c( thing1 = 0 , thing2 = 100 ),
rows = 5
),
waffle(
parts = c( thing1 = 25 , thing2 = 75 ),
rows = 5
)
)
Tanpa (Anda dapat menonaktifkan ini melalui parameter keep
sekarang):
iron(
waffle(
parts = c( thing1 = 0 , thing2 = 100 ),
rows = 5 ,
keep = FALSE
),
waffle(
parts = c( thing1 = 25 , thing2 = 75 ),
rows = 5 ,
keep = FALSE
)
)
Riasan Tenaga Kerja Profesional
Contoh besi (rata kiri & padding untuk beberapa plot)
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()
Lang | # File | (%) | LoC | (%) | Garis kosong | (%) | # Garis | (%) |
---|---|---|---|---|---|---|---|---|
R | 14 | 0,44 | 624 | 0,35 | 218 | 0,36 | 439 | 0,38 |
RMD | 2 | 0,06 | 255 | 0,15 | 88 | 0,14 | 139 | 0,12 |
JUMLAH | 16 | 0,50 | 879 | 0,50 | 306 | 0,50 | 578 | 0,50 |
{jam} ? metrik untuk wafel
Harap dicatat bahwa proyek ini dirilis dengan Kode Etik Kontributor. Dengan berpartisipasi dalam proyek ini, Anda setuju untuk mematuhi ketentuannya.