library(gt) library(dplyr) ## ## 载入程辑包:'dplyr' ## The following objects are masked from 'package:stats': ## ## filter, lag ## The following objects are masked from 'package:base': ## ## intersect, setdiff, setequal, union
islands_tbl ## # A tibble: 10 x 2 ## name size ## <chr> <dbl> ## 1 Asia 16988 ## 2 Africa 11506 ## 3 North America 9390 ## 4 South America 6795 ## 5 Antarctica 5500 ## 6 Europe 3745 ## 7 Australia 2968 ## 8 Greenland 840 ## 9 New Guinea 306 ## 10 Borneo 280
接下来制作一个简单的表格:
gt_tbl <- gt(islands_tbl) gt_tbl
这就是一个简单表格。接下来我们就按照gt包分解表格的理念一步步添加各种细节。
添加标题
gt_tbl <- gt_tbl %>% tab_header( title = "Large Landmasses of the World", subtitle = "The top ten largest are presented" ) gt_tbl
更牛逼的是,这个标题支持markdown语法!
gt(islands_tbl[1:2,]) %>% tab_header( title = md("**Large Landmasses of the World**"), subtitle = md("The *top two* largest are presented") )
添加脚注
使用tab_source_note()函数,同样也是支持markdown语法的。
gt_tbl <- gt_tbl %>% tab_source_note( source_note = "Source: The World Almanac and Book of Facts, 1975, page 406." ) %>% tab_source_note( source_note = md("Reference: McNeil, D. R. (1977) *Interactive Data Analysis*. Wiley.") )