11# ' Internal function to generate hex sticker
22# ' @keywords internal
33generate_cansim_hex_sticker <- function (){
4- income_data <- cansim :: get_cansim(" 11-10-0239" ) %> %
5- cansim :: normalize_cansim_values()
64 income_age_groups <- c(" 16 to 24 years" , " 25 to 34 years" , " 35 to 44 years" , " 45 to 54 years" ," 55 to 64 years" , " 65 years and over" )
7- income_plot_data <- income_data %> %
5+ income_plot_data <- cansim :: get_cansim_connection( " 11-10-0239 " ) %> %
86 dplyr :: filter(Sex == " Both sexes" ,
97 Statistics == " Median income (excluding zeros)" ,
108 `Income source` == " Total income" ,
119 `Age group` %in% income_age_groups ) %> %
10+ cansim :: collect_and_normalize() %> %
1211 dplyr :: mutate(`Age group` = factor (`Age group` ,levels = income_age_groups )) %> %
1312 dplyr :: group_by(GEO ,`Age group` ) %> %
1413 dplyr :: left_join(dplyr :: filter(. ,Date == min(Date )) %> %
@@ -19,15 +18,39 @@ generate_cansim_hex_sticker <- function (){
1918 pd <- income_plot_data %> % dplyr :: filter(GEO == " Canada" )
2019 ed <- pd %> % dplyr :: filter(Date == max(Date ))
2120
22- ca_data <- cancensus :: get_census(" CA16" ,regions = list (C = " 01" ),geo_format = ' sf' ) %> % sf :: st_transform(102002 )
21+ crs <- ' PROJCS["Canada_Lambert_Conformal_Conic",
22+ GEOGCS["NAD83",
23+ DATUM["North_American_Datum_1983",
24+ SPHEROID["GRS 1980",6378137,298.257222101,
25+ AUTHORITY["EPSG","7019"]],
26+ AUTHORITY["EPSG","6269"]],
27+ PRIMEM["Greenwich",0,
28+ AUTHORITY["EPSG","8901"]],
29+ UNIT["degree",0.0174532925199433,
30+ AUTHORITY["EPSG","9122"]],
31+ AUTHORITY["EPSG","4269"]],
32+ PROJECTION["Lambert_Conformal_Conic_2SP"],
33+ PARAMETER["latitude_of_origin",40],
34+ PARAMETER["central_meridian",-96],
35+ PARAMETER["standard_parallel_1",50],
36+ PARAMETER["standard_parallel_2",70],
37+ PARAMETER["false_easting",0],
38+ PARAMETER["false_northing",0],
39+ UNIT["metre",1,
40+ AUTHORITY["EPSG","9001"]],
41+ AXIS["Easting",EAST],
42+ AXIS["Northing",NORTH],
43+ AUTHORITY["ESRI","102002"]]'
44+
45+ ca_data <- cancensus :: get_census(" CA16" ,regions = list (C = " 01" ),geo_format = ' sf' ) %> % sf :: st_transform(crs )
2346 q <- ggplot2 :: ggplot(ca_data ) +
2447 ggplot2 :: geom_sf(fill = " grey20" ,size = 0.01 ) +
2548 ggplot2 :: theme_void() +
2649 hexSticker :: theme_transparent()
2750 bbox = sf :: st_bbox(ca_data )
2851 p <- ggplot2 :: ggplot(pd ,ggplot2 :: aes(x = Date ,y = VALUE ,color = `Age group` )) +
2952 ggplot2 :: geom_line() +
30- ggplot2 :: scale_color_brewer(palette = " Dark2" ,guide = FALSE ) +
53+ ggplot2 :: scale_color_brewer(palette = " Dark2" ,guide = ' none ' ) +
3154 ggplot2 :: labs(x = " " ,y = " " ) +
3255 ggplot2 :: theme_void() +
3356 hexSticker :: theme_transparent()
@@ -45,6 +68,16 @@ generate_cansim_hex_sticker <- function (){
4568 p_color = " white" ,
4669 filename = here :: here(" images/cansim-sticker.png" ))
4770
71+ if (FALSE ) {
72+ hexSticker :: sticker(pp , package = " CanViz" ,
73+ p_size = 8 , p_y = 1.5 ,
74+ s_x = 1 , s_y = 0.78 , s_width = 1.5 , s_height = 1.5 ,
75+ h_color = " #FF0000" ,
76+ h_fill = " grey40" ,
77+ p_color = " white" ,
78+ filename = here :: here(" ~/Downloads/canviz-sticker.svg" ))
79+ }
80+
4881}
4982
5083# ' Internal function to update table list
0 commit comments