本文主要是介绍拼凑sql_R中的拼凑包,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
拼凑sql
Patchwork is a package for the R programming language that simplifies data visualization layouts through a simple math-like syntax.
Patchwork是R编程语言的软件包,可通过类似于数学的简单语法简化数据可视化布局。

The Composer of ggplots
ggplots的作曲家
With Patchwork the task of combining and organizing ggplots is very easy and can produce ornate visualizations with simple code.
使用Patchwork ,组合和组织ggplots的任务非常容易,并且可以使用简单的代码产生华丽的可视化效果。
All charts here are made with sample data sets and are just used for example purposes.
这里的所有图表都是用示例数据集制作的,仅用于示例目的。
简单图表组合 (Simple Chart Combinations)
垂直堆叠的图表 (Vertically Stacked Charts)
If i wanted to take a couple charts of mind and compare them next to each other either one above the other it may look something like this:
如果我想拍几张思维图,然后将它们彼此比对,则可能看起来像这样:

Looking at this code what we do is create 2 ggplots and assign each to their own variable, top
and bottom
respectively.
看这段代码,我们要做的是创建2个ggplots,并将每个ggplots分别分配给它们自己的变量top
和bottom
。
Conveniently named we can see where each is going to be placed in the final visual.
方便命名,我们可以看到每个元素在最终视觉效果中的放置位置。
The simple Patchwork syntax is finding those 2 variables at the bottom and with a simple division sign saying that top
should be divided by bottom
.
简单的Patchwork语法是在底部找到这两个变量,并带有一个简单的除号,表示top
应除以bottom
。
The syntax is super transparent and intuitive with what it will do with the plots and how you might structure more advanced combinations later on. For now, the stacked visualization will look like
该语法具有极高的透明度和直观性,可用于处理图以及以后如何构造更高级的组合。 现在,堆叠的可视化效果看起来像

水平堆放 (Horizontal Stacking)
If you wanted to stack your plots horizontally its as simple as adding them together:
如果您想水平堆叠地图,就像将它们加在一起一样简单:

With the +
operator you can add charts together flowing from left to right and we show this with the above defined variables conveniently named left
and right
:
使用+
运算符,您可以将图表从左到右加在一起,并使用方便地命名为left
和right
的上述定义的变量进行显示:

It is also useful to know that using the |
pipe operator you can equally divide the sections of the final aggregate visual. So if i ran this code:
知道使用|
是非常有用的|
管道运算符,您可以平均划分最终聚合视觉的各个部分。 因此,如果我运行此代码:

My output would actually look like a 50/25/25 split between the charts:
我的输出实际上看起来像图表之间的50/25/25分割:

溢出和定义网格 (Overflowing and Defining The Grid)
So that is a quick way of putting some visualizations together, what are some more elaborate uses of Patchwork and some of its behavior?
因此,这是将某些可视化组合在一起的快速方法,Patchwork的一些更精细的用法及其行为是什么?
If we add a bunch of charts together with the +
operator would it just squeeze the plots together until there’s no room left? We now know that the |
will evenly divide available space between the plots, so the more we add the evenly divided space will get more cramped over time. With that known what does adding a lot of plots together achieve?
如果我们将一堆图表与+
运算符一起添加,会不会只是将图表挤压在一起,直到没有剩余空间了? 我们现在知道|
会在地块之间平均分配可用空间,因此,随着时间的推移,我们添加的均分空间越多,局限性就会越来越大。 有了这些已知的知识,将很多地块加在一起就能达到什么目的?

So Patchwork will try to keep the plots in a square grid shaped combination with the usage of +
so if we have 4 plots we should expect a 2x2 grid square combo plot:
因此,Patchwork将尝试使用+
将地块保持在正方形网格形状的组合中,因此,如果我们有4个地块,我们应该期望2x2网格正方形组合地块:

This is helpful so that at least with minimal tampering everything is somewhat visible and less squished than if we used the |
to combine the plots.
这很有用,因此与我们使用|
相比,至少可以以最小程度的篡改来使所有内容都稍微可见一些,并且压缩起来更少|
合并地块。
You can imagine this grid behavior as plots moving into available slots in an assembly line fashion. The first row (slots 1 and 2) must be filled before flowing down to Row 2 to fill slots 3 and 4.
您可以想象这种网格行为是随着绘图以装配线方式移动到可用插槽中。 必须先填充第一行(插槽1和2),然后向下流入第2行以填充插槽3和4。
Lets say you what to redefine the dimensions of your grid so that you have 3 rows, and 2 columns (a 3x2 grid) and you want to fill the grid by columns not rows. You can imagine the assembly line filling in your grid from top to bottom slot 1, 2, then 3, and finally the top slot of column 2 for the 4th plot.
假设您要重新定义网格尺寸的内容,以便拥有3行和2列(3x2网格),并且希望按列而非行填充网格。 您可以想象装配线从第1排,第2排,第3排,第3排,最后是第4列的第2列的顶部排填充到网格中。
How do we achieve this with Patchwork syntax?
我们如何使用Patchwork语法实现这一目标?

What we’re saying is add +
all the plots together and overflow the grid, but with plot_layout
we define with nrow
that we want the grid to have 3 rows, and byrow
is asking the question “Should i fill each row first before moving down to the next?” and we’re saying No, Fill each column first then move to the next:
我们要说的是增加+
所有的情节一起溢出电网,但plot_layout
我们有定义nrow
我们想要的电网有3排,并byrow
在问这个问题:“ 我应该向下移动之前,首先要填写每一行到下一个? ”,我们说的是“ 否” ,请先填充每一列,然后再移至下一列:

堆叠与包装 (Stacking and Packing)
Overflowing the grid is useful but still, you say you want more granular control of the layout? Say no more, we can combine multiple operators to achieve this.
网格的溢出很有用,但您仍然说要对布局进行更精细的控制吗? 无需多说,我们可以合并多个运算符来实现此目的。

So what is going on here? You might be able to guess what this might look like by now, but just in case lets read it from inside out.
那么这是怎么回事? 您也许能够猜测到现在的样子,但是以防万一,让我们从内而外阅读它。
We’re saying take the
top
chart and place thebottom
chart below it in a vertically stacked combo我们是说拿
top
图表,然后将bottom
图表放在其bottom
的垂直堆叠组合中Then we have a combination of the
left
chart taking up the left half and the combo oftop
andbottom
taking up the right half然后,我们将
left
占据了左半部分,而top
和bottom
组合占据了右半部分And finally we take that 3 part combo chart and put the
right
chart underneath it to finish it off.最后,我们采用该三部分组合图并将
right
图放在其下以完成该过程。
You can see how with some simple order of operations (we all remember the PEMDAS acronym from algebra right?) we can easily and logically control the layout of the plots. Lets see the fruits of our labor:
您可以看到如何用一些简单的操作顺序( 我们都记得 代数中 的 PEMDAS 缩写吗? )可以轻松而合理地控制图的布局。 让我们看看我们劳动的成果:

This isn’t the prettiest example but you can see by this example the power and flexibility that Patchwork give you with your layouts.
这不是最漂亮的示例,但是您可以通过此示例看到Patchwork为您的布局提供的功能和灵活性。
HOWEVER! We left one important thing out, we need to name our Franken-Plot, but with so many pieces involved in this…. Patchwork Plot…. Sorry, I’ll stop. With so many pieces how do we appropriately name the whole aggregate visual?
然而! 我们遗漏了一件重要的事情,我们需要命名弗兰肯情节,但其中涉及很多方面……。 拼布图...。 对不起,我停一下。 有这么多片段,我们如何恰当地命名整体视觉效果?
By adding one more thing:
通过添加另一件事:

plot_annotation
will let us appropriately title the whole aggregate visualization in the top left:
plot_annotation
将让我们在左上方适当地plot_annotation
整个聚合可视化:

Ugly visualizations aside you can see the gold of the Patchwork package shine through and the value it could provide you in your work with R.
除了丑陋的可视化效果之外,您还可以看到Patchwork程序包的金色光芒,以及它在使用R时可以为您提供的价值。
运营商及其工作概述 (Quick Summary of The Operators and What They Do)
A Quick Recap of the various operators and functions covered:
所涵盖的各种运算符和功能的快速回顾:
+
Add plots together, defaults left to right, overflows the grid+
将图加在一起,默认从左到右,使网格溢出/
Divide plots, Put Left hand side on top of right hand side/
划分图,将左手边放在右手边的顶部|
Evenly separate plots into equal sized portions based on how many|
are used:one | two | three
produces 3 x 33.33% slots|
根据多少|
将地块平均分成相等大小的部分 使用:one | two | three
one | two | three
one | two | three
产生3 x 33.33%的插槽(
&)
are used for order of operations “Do This First then the stuff outside of us”(
&)
用于操作顺序“先执行此操作,然后进行外部操作”
谢谢! (Thanks!)
码? (Code?)
If you would like all the example code used in the video / this article you can grab it here:
如果您想要视频/本文中使用的所有示例代码,可以在这里获取:
翻译自: https://medium.com/analytics-vidhya/the-patchwork-package-in-r-9468e4a7cd29
拼凑sql
相关文章:
这篇关于拼凑sql_R中的拼凑包的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!