千牛包表包下载_探索R中表包的gt语法

千牛包表包下载

I love migrittr’s forward-pipe %>% operator. IMO, it is just the one of the most fitting, useful and natural, almost reflex like operator in all programming. In the past, it has propelled the tidyverse to data wrangling superstardom and it is now venturing into the task of making tables dramatically easy.

我喜欢migrittr的前管%>%运算符。 IMO,它是所有编程中最合适,最有用,最自然,几乎像反射一样的运算符之一。 过去,它已将tidyverse推向了争夺超级明星的数据,现在正冒险使表变得非常容易的任务。

The gt package is the latest ambitious entry to make tables in R more accessible, modifiable and reproducible. It is aimed at being the ggplot2 for tables (in Hadley’s words, not mine) and given the magnanimous impact that the former had on the R viz, the package comes with immense pressure of its shoulders.

gt软件包是最新的雄心勃勃的条目,它可以使R中的表更易于访问,修改和再现。 它的目的是作为桌子的ggplot2(用Hadley的话说,不是我的),并且鉴于前者对R viz产生的巨大影响,该包装的肩膀承受着巨大的压力。

Here’s an illustration of the architecture of the gt package —

这是gt包的体系结构的说明-

Image for post
The Grammar Of Tables Layout. Source — GT Documentation, R Studio
表布局语法。 来源— GT Studio,R Studio

We will be using the palmer penguins data, an alternative to the now infamous iris dataset. You can download the data here!

我们将使用帕尔默企鹅数据,这是现在臭名昭著的虹膜数据集的替代方法。 您可以在此处下载数据!

Post performing basic tidyverse verbs to filter and group the data in the desired shape, we invoke the gt() command and specify the desired row.

在执行基本的tidyverse动词以按所需形状过滤和分组数据后,我们调用gt()命令并指定所需行。

Image for post
Image for post

Add Column Spanners

添加列扳手

As evident, the above data is the simplest and rawest data table created. We now proceed to format it. We begin by adding column spanners and bringing male and female columns in their respective hood and customise their font and alignment.

显而易见,以上数据是创建的最简单和最原始的数据表。 现在,我们进行格式化。 我们首先添加列扳手,并将公母列带入各自的罩中,然后自定义其字体和对齐方式。

Image for post
Image for post

Create Row Summary Statistics & Format Data

创建行摘要统计信息和格式数据

We can also add a descriptive statistic specifying mean or totals per metric within the table. This could enable relative comparison and could lead to rich insights. Here, I have calculated the yearly average bill length, bill depth and flipper in each island and formatted the number to include no decimals.

我们还可以在表中添加描述性统计信息,以指定每个指标的平均值或总计。 这样可以进行相对比较,并可以得出丰富的见解。 在这里,我计算了每个岛屿的年平均账单长度,账单深度和脚蹼,并对数字进行了格式化,使其不包含小数。

Image for post
Image for post

Add Colour & Footnote

添加颜色和脚注

Now the fun part, I have used one of the plethora of palettes available via the palatteer package and conditionally formatted shade of the table in accordance to the numeric value of the cell it represents. The gt package also a feature to add a footnote to the table. I have used it here to specify the metric in which the bill length, bill depth and flipper length and body mass is measured.

现在最有趣的部分是,我使用了可通过palatteer软件包获得的大量调色板之一,并根据表所表示的单元格的数值对表进行了条件格式化。 gt包还具有在表中添加脚注的功能。 我在这里使用它来指定度量标准,在该度量标准中可以测量钞票长度,钞票深度以及脚蹼长度和体重。

Image for post
Image for post

Add Table Title, Subtitle & Change Column Labels

添加表格标题,字幕和更改列标签

While the colours have bought in buoyancy to the table, a title is much needed. The package also enables the use of markdown text in the title/subtitle. Here I have used the emo::ji package to add cute little penguin emoji’s in my title. Since the column labels were still messy, I have also renamed & formatted column tables to a shorter, more readable title.

尽管桌子上的颜色使它们浮起来,但仍然很需要标题。 该包还允许在标题/副标题中使用降价文字。 在这里,我使用emo::ji包在标题中添加了可爱的小企鹅表情符号。 由于列标签仍然杂乱无章,因此我还对列表进行了重命名和格式化,以使其标题更短,更易读。

Image for post
Image for post

Add Background Colour & Format Borders

添加背景颜色和格式边框

I know proceed to add custom colours to the remaining whitespace, i.e title, subtitle, row average and footnote. I have specified the desired HEX code referring to this colour brewer for aesthetic advice . I have also added dotted borders to the year rows and have thickened the borders along the island rows to amplify differentiation and boost readability.

我知道继续为剩余的空白添加自定义颜色,即标题,副标题,行平均值和脚注。 我已经指定了与色料调制器相关的所需十六进制代码,以提供美学建议。 我还为年份行添加了虚线边框,并增加了沿岛行的边框,以扩大差异性并提高可读性。

Image for post
Image for post

Adjust Font , Alignment & Add Source Note

调整字体,对齐方式并添加源注释

As a last finishing touch and i order to ensure font uniformity, I have applied the Oswald font across the table and have centre aligned each cell. Lastly, below the footnote, I have added a source-note that states the data source.

最后,为了确保字体均匀性,我在表格上应用了Oswald字体,并使每个单元格居中对齐。 最后,在脚注下方,我添加了一个注明数据源的来源说明。

Image for post
Image for post

And that’s the final masterpiece! :D

这就是最终的杰作! :D

Hope you enjoyed reading. You can reach out to me here & here!

希望您喜欢阅读。 您可以在这里这里与我联系!

翻译自: https://towardsdatascience.com/exploring-the-gt-grammar-of-tables-package-in-r-7fff9d0b40cd

千牛包表包下载

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值