Warning: Since gt v0.9.0, the `colors` argument has been deprecated.
• Please use the `fn` argument instead.
This warning is displayed once every 8 hours.
Tingkat Kebahagiaan Negara ASEAN Menurut WVS 7
Negara
Kebahagiaan
Malaysia
1.972
Singapura
1.860
Thailand
1.845
Myanmar
1.825
Indonesia
1.630
Filipina
1.584
Vietnam
1.552
Source: https://www.worldvaluessurvey.org/wvs.jsp
(happy_tbl <- happy_tbl%>%#All column headers are capitalisedopt_all_caps() %>%#Use the Chivo font#Note the great 'google_font' function in 'gt' that removes the need to pre-load fontsopt_table_font(font =list(google_font("Chivo"),default_fonts() ) ) %>%#Change the width of columnscols_width(c(Kebahagiaan) ~px(150),c(Negara) ~px(400)) %>%tab_options(#Remove border between column headers and titlecolumn_labels.border.top.width =px(3),column_labels.border.top.color ="transparent",#Remove border around tabletable.border.top.color ="transparent",table.border.bottom.color ="transparent",#Reduce the height of rowsdata_row.padding =px(3),#Adjust font sizes and alignmentsource_notes.font.size =12,heading.align ="left" ))
Tingkat Kebahagiaan Negara ASEAN Menurut WVS 7
Negara
Kebahagiaan
Malaysia
1.972
Singapura
1.860
Thailand
1.845
Myanmar
1.825
Indonesia
1.630
Filipina
1.584
Vietnam
1.552
Source: https://www.worldvaluessurvey.org/wvs.jsp
3.2 add image
#To convert country codeslibrary(countrycode)flag_db <-read.csv("Country_Flags.csv") %>%#Convert country names into 3-letter country codesmutate(Code =countrycode(sourcevar =Country, origin ="country.name", destination ="iso3c", warn =FALSE)) %>%select(Code, flag_URL = ImageURL)flag_data <- wvs %>%left_join(flag_db, by ="Code") %>%select(flag_URL, Negara, everything())#We'll need to refit our table using this new data#Code below with comments removed.wb_table <-head(flag_data) %>%gt() %>%cols_hide(columns =c(Code)) %>%cols_label(Negara ="Country",Kebahagiaan ="Kebahagiaan") %>%tab_header(title =md("Tingkat Kebahagiaan Negara ASEAN")) %>%tab_source_note(source_note ="Sumber Data: World Values Survey 7 ") %>%fmt_number(columns =c(Kebahagiaan),scale_by =1) %>%cols_label(Kebahagiaan ="Kebahagiaan") %>%tab_style(locations =cells_column_labels(columns =everything()),style =list(cell_borders(sides ="bottom", weight =px(3)),cell_text(weight ="bold") ) ) %>%tab_style(locations =cells_title(groups ="title"),style =list(cell_text(weight ="bold", size =25) ) ) %>%data_color(columns =c(Kebahagiaan),colors = hepi_palette) %>%opt_all_caps() %>%opt_table_font(font =list(google_font("Chivo"),default_fonts() ) ) %>%cols_width(c(Kebahagiaan) ~px(150),c(Negara) ~px(300)) %>%tab_options(column_labels.border.top.width =px(3),column_labels.border.top.color ="transparent",table.border.top.color ="transparent",table.border.bottom.color ="transparent",data_row.padding =px(3),source_notes.font.size =12,heading.align ="center")wb_table %>% gt::text_transform(#Apply a function to a columnlocations =cells_body(c(flag_URL)),fn =function(x) {#Return an image of set dimensionsweb_image(url = x,height =12 ) } ) %>%#Hide column header flag_URL and reduce widthcols_width(c(flag_URL) ~px(30)) %>%cols_label(flag_URL ="")