🏷️

Plotting with categorical data

서문

In the relational plot tutorial we saw how to use different visual representations to show the relationship between multiple variables in a dataset. In the examples, we focused on cases where the main relationship was between two numerical variables. If one of the main variables is “categorical” (divided into discrete groups) it may be helpful to use a more specialized approach to visualization.
앞선 relational plot 튜토리얼에서는 하나의 데이터셋 속 여러가지 변수들 간의 관계를 어떻게 시각화 하는지 보았다. 메인 변수로 두 가지 수치형(numerical) 변수들을 놓고 서로의 관계를 파악하는 것이 주로 든 예시들이었다. 만약 그 메인 변수들 중 하나가 수치화된 데이터가 아닌 "범주형 변수(각각이 그룹으로 나뉠 수 있는)"라면, 시각화함에 있어 좀 더 특화된 접근법이 더 유용하다고 본다.
In seaborn, there are several different ways to visualize a relationship involving categorical data. Similar to the relationship between relplot() and either scatterplot() or lineplot(), there are two ways to make these plots. There are a number of axes-level functions for plotting categorical data in different ways and a figure-level interface, catplot(), that gives unified higher-level access to them.
Seaborn에서 범주형 데이터를 포함한 변수들의 관계를 시각화하는 데에는 여러가지 방법들이 있다. relplot() 안에도 산점도 방식과 선 그래프 방식이 있었던 것처럼, 범주형 변수를 시각화하는 방식에도 두 가지 방식이 존재한다. 우선 (기본적으로 통계적 관계를 시각화하는) Figure-level의 인터페이스로는 catplot()이 있다. catplot()의 인터페이스는 범주형 데이터들을 다루는데 있어서 한 단계 높은 접근성을 갖고 있다. 또 다른 방법 중 하나인 axes-level에 속하는 방법도 여럿이 있다.
( 역주 : catplot()과 같은 Figure-level의 클래스들이 한 단계 높다는 말은 아마도 catplot()이 kind="" 인자argument 입력을 통해 다양한 유형의 그래프로 유연한 활용이 가능하기 때문일 것이다)
It’s helpful to think of the different categorical plot kinds as belonging to three different families, which we’ll discuss in detail below. They are:
범주형 데이터들을 시각화하는 방식을 크게 3가지로 구분하면 기억하는데에 도움이 될 것이다. 아래에 자세히 기술해 두었다 :
Categorical scatterplots:
stripplot() (with kind="strip"; the default)
swarmplot() (with kind="swarm")
Categorical distribution plots:
boxplot() (with kind="box")
violinplot() (with kind="violin")
boxenplot() (with kind="boxen")
Categorical estimate plots:
pointplot() (with kind="point")
barplot() (with kind="bar")
countplot() (with kind="count")
These families represent the data using different levels of granularity. When deciding which to use, you’ll have to think about the question that you want to answer. The unified API makes it easy to switch between different kinds and see your data from several perspectives.
각각의 방식은 데이터를 각기 다른 수준으로 세분화한다. 어떤 걸 사용할지 결정할 때에는, 스스로 해결하고자 하는 질문을 먼저 구상해야 한다. catplot() 으로 통일되어 있는 API는 각기 다른 kind 를 통해 손쉽게 여러 모습으로 데이터를 표현할 수 있도록 만들어준다.
In this tutorial, we’ll mostly focus on the figure-level interface, catplot(). Remember that this function is a higher-level interface each of the functions above, so we’ll reference them when we show each kind of plot, keeping the more verbose kind-specific API documentation at hand.
이번 튜토리얼에서는 catplot()을 사용하는 것에 집중할 것이다. 이 기법은 위에서 언급한 클래스들보다 한 단계 높은 단계의 클래스이며, 그렇기에 catplot()을 통해 도표를 그릴 때마다 그에 해당하는 부속 단계 클래스에 대해서도 계속 언급할 것이다. 훨씬 다양한 종류의 API에 대한 문서도 지속적으로 참고할 것이다
import seaborn as sns import matplotlib.pyplot as plt sns.set(style="ticks", color_codes=True)
Python

Categorical scatterplots¶

범주형 산점도
The default representation of the data in catplot() uses a scatterplot. There are actually two different categorical scatter plots in seaborn. They take different approaches to resolving the main challenge in representing categorical data with a scatter plot, which is that all of the points belonging to one category would fall on the same position along the axis corresponding to the categorical variable. The approach used by stripplot(), which is the default “kind” in catplot() is to adjust the positions of points on the categorical axis with a small amount of random “jitter”:
catplot()의 기본적인 데이터 표현은 산점도이다. Seaborn에는 사실 두 가지 종류의 범주형 산점도가 있다. 범주에 따라 나뉘는 데이터를 산점도로 표현하는 데에 가장 큰 난관은 축axis의 레이블label 자리에(즉, 각 범주가 표기되는 자리 - matplotlib의 tick과 label을 생각하면 쉽게 이해할 수 있다.) 일렬로 점이 찍혀버리는 현상을 해결하는 것이다.
tick 개념을 쉽게 이해하기 위한 이미지
이에 그 두 가지 기법은 각기 다른 해결책을 사용하고 있다. catplot()의 기본 kindstripplot()은 카테고리마다 일렬로 세우긴 하되, 약간씩 랜덤한 거리 조절 (jitter 라고 부르는 노이즈) 을 둔다.
tips = sns.load_dataset("tips") sns.catplot(x="day", y="total_bill", data=tips);
Python
The jitter parameter controls the magnitude of jitter or disables it altogether:
jitter 인자는 이때 그 거리조절의 크기를 상정하거나, 아예 비활성화할 수도 있는 인자이다.
sns.catplot(x="day", y="total_bill", jitter=False, data=tips);
Python
얼마나 뭉쳐있는지를 파악할 수 없다.
The second approach adjusts the points along the categorical axis using an algorithm that prevents them from overlapping. It can give a better representation of the distribution of observations, although it only works well for relatively small datasets. This kind of plot is sometimes called a “beeswarm” and is drawn in seaborn by swarmplot(), which is activated by setting kind="swarm" in catplot():
두 번째 방식은 구분선 위에 놓일 점들이 겹치지 않도록 알고리즘을 이용하는 것이다. 관찰되는 분포를 나타내기엔 이게 더 좋은 방법이 될 수 있다. 물론 데이터가 상대적으로 작은 상황에 잘 적용되는 것이긴 하지만.
위와 같은 방식의 도표를 때때로 "벌떼" 라고 부르며 Seaborn에서는 swarmplot() 을 통해 구현한다. 물론 catplot()에서 kind="swarm" 이라는 인자를 통해 구현하는 것도 가능하다.
sns.catplot(x="day", y="total_bill", kind="swarm", data=tips);
Python
Similar to the relational plots, it’s possible to add another dimension to a categorical plot by using a hue semantic. (The categorical plots do not currently support size or style semantics). Each different categorical plotting function handles the hue semantic differently. For the scatter plots, it is only necessary to change the color of the points:
relplot()과 유사하게, hue를 통한 의미 구분 기법을 사용해 하나의 범주 차원을 추가하는 게 가능하다. (아직 size와 style 을 통한 의미 구분 기법은 지원하고 있지 않다) 범주형 플롯의 도표들은 각기 다른 방식으로 hue를 통한 의미 구분 기법을 조절한다. 일단 산점도에서는, 점의 색을 바꾸기만 하면 된다.
sns.catplot(x="day", y="total_bill", hue="sex", kind="swarm", data=tips);
Python
Unlike with numerical data, it is not always obvious how to order the levels of the categorical variable along its axis. In general, the seaborn categorical plotting functions try to infer the order of categories from the data. If your data have a pandas Categorical datatype, then the default order of the categories can be set there. If the variable passed to the categorical axis looks numerical, the levels will be sorted. But the data are still treated as categorical and drawn at ordinal positions on the categorical axes (specifically, at 0, 1, …) even when numbers are used to label them:
수치형 데이터와는 다르게, 범주형 데이터들은 구분의 순서들이 늘 명확하진 않다. Seaborn은 일반적으로 데이터 셋 안에서 그 범주들이 어떤 순서로 구분되어 있는지가 반영한다. 만약 데이터가 pandas 라이브러리의 범주형 데이터 타입이라면 그걸 따라 기본 순서가 결정된다. 만약 변수가 범주형일지라도 어느정도 넘버링이 가능해보인다면, 그 넘버링 순서에 따라 정렬된다. 하지만 여전히 범주형으로 취급되며 오름차순으로 정렬된다. 숫자 자체가 x축의 레이블(label)이 될 때도 이 규칙은 적용된다 :
sns.catplot(x="size", y="total_bill", kind="swarm", data=tips.query("size != 3"));
Python
The other option for choosing a default ordering is to take the levels of the category as they appear in the dataset. The ordering can also be controlled on a plot-specific basis using the order parameter. This can be important when drawing multiple categorical plots in the same figure, which we’ll see more of below:
다른 방법은 데이터 셋 안에서 드러나는 범주 순서를 바로 순서에 반영하는 것이다. 이때 순서 배정은 그래프를 그리고 직접 조절할 수 있다. (order=[] 에 파라미터를 넣어서 사용한다) 이건 하나의 그래프에 여러가지 범주를 두어 그릴 때 중요할 수 있다 (subsets 그래프를 그린다는 의미이다). 다음과 같은 예시를 준비했다 :
sns.catplot(x="smoker", y="tip", order=["No", "Yes"], data=tips);
Python
We’ve referred to the idea of “categorical axis”. In these examples, that’s always corresponded to the horizontal axis. But it’s often helpful to put the categorical variable on the vertical axis (particularly when the category names are relatively long or there are many categories). To do this, swap the assignment of variables to axes:
"범주 구분의 축categorical axis"이라는 개념을 계속 언급해왔는데, 이때까지의 예시들은 모두 수평 방향 (x축 방향)에 따른 구분이었다. 그러나 범주 구분을 수직 방향에 따라 그려보는 것도 대개는 도움이 된다. (특히나 범주의 이름이 상대적으로 길거나 범주의 수가 많을 때 도움이 된다) 이를 위해서는 각 변수들 (x 축에 배치된 변수와 y축에 배치된 변수) 의 축을 바꿔서 배치하면 된다.
sns.catplot(x="total_bill", y="day", hue="time", kind="swarm", data=tips);
Python

Distributions of observations within categories¶

범주 안에서 보여지는 각각의 분포들에 대해서
As the size of the dataset grows, categorical scatter plots become limited in the information they can provide about the distribution of values within each category. When this happens, there are several approaches for summarizing the distributional information in ways that facilitate easy comparisons across the category levels.
데이터셋의 크기 자체가 점차 커지면, 각 카테고리의 영역 안에서 점들을 찍어 표현하는 방법은 데이터 분포 정보까지 전달하기엔 한계가 있다. 이러한 상황에서는 그 분포 정보를 요약하는 접근법이 여럿 있다. 그 방법을 통해서라면 figure-level과 axes-level의 그래프 모두를 쉽게 비교하는 게 가능하다.

Boxplots

수염상자그림
The first is the familiar boxplot(). This kind of plot shows the three quartile values of the distribution along with extreme values. The “whiskers” extend to points that lie within 1.5 IQRs of the lower and upper quartile, and then observations that fall outside this range are displayed independently. This means that each value in the boxplot corresponds to an actual observation in the data.
그 첫번째 방법은 우리에게 친숙한 수염상자그림이다 (박스플롯). 이건 극단치 (아웃라이어)들을 포함한 값들의 분산들로부터 3개의 분위수(상, 중, 하 분위수)를 보여준다. "수염"은 높은 분위수(상 분위수)로부터 1.5 IQR만큼 높은 값까지를 포섭하고, 그 범위를 벗어난 데이터는 각각 독립적으로 표현된다. 다시 말하자면, 박스플롯에 의한 각 데이터들은 그 데이터의 실제값에 대응된다는 것이다.
sns.catplot(x="day", y="total_bill", kind="box", data=tips);
Python
When adding a hue semantic, the box for each level of the semantic variable is moved along the categorical axis so they don’t overlap:
이때 hue에 의한 의미구분을 더하면, 그에 따라 추가된 변수의 박스가 범주 구분의 축categorical axis (위 그림에서는 요일)에 따라 붙으며, 두 박스가 겹쳐 표현되진 않는다.
sns.catplot(x="day", y="total_bill", hue="smoker", kind="box", data=tips);
Python
This behavior is called “dodging” and is turned on by default because it is assumed that the semantic variable is nested within the main categorical variable. If that’s not the case, you can disable the dodging:
이러한 걸 "닷징(피하기)" 이라고 부르는데, 기본 옵션으로 적용되는 기능이기도 하다. 흔히 hue 등으로 의미구분을 더한다는 건, 메인 범주들 안에서 다시 한번 구분을 하는 행위라고 간주되기 때문이다. 만약 그런 케이스가 아니라면, 닷징 기능을 무력화하기도 가능하다. (아래 예시 참고)
tips["weekend"] = tips["day"].isin(["Sat", "Sun"]) sns.catplot(x="day", y="total_bill", hue="weekend", kind="box", dodge=False, data=tips);
Python
( 역주 : hue 와 같은 기능을 쓰게 되면 그 구분에 따라 그래프가 여러개 생기게 되고, 그 그래프들이 겹쳐 표현되지 않는 걸 '닷징'이라 부르고 있다. 이는 아래서 배울 스플릿split 개념을 알면 더 이해가 쉽다.)
A related function, boxenplot(), draws a plot that is similar to a box plot but optimized for showing more information about the shape of the distribution. It is best suited for larger datasets:
이와 연관된 기능인 박슨플롯boxenplot()(마땅한 번역어가 없어서 그냥 씁니다) 박스 플롯과 비슷한 도표를 그리기는 하지만, 그 분포의 "모양"을 좀 더 전달하는데 최적화되어 있다. 좀 더 큰 데이터셋에게 적합한 기능이다.
diamonds = sns.load_dataset("diamonds") sns.catplot(x="color", y="price", kind="boxen", data=diamonds.sort_values("color"));
Python

Violinplots

바이올린 플롯
A different approach is a violinplot(), which combines a boxplot with the kernel density estimation procedure described in the distributions tutorial:
또 다른 접근법은 바이올린 플롯이다. 수염상자그림과 커널밀도추정 기법을 혼합해 분포를 묘사한다.
sns.catplot(x="total_bill", y="day", hue="sex", kind="violin", data=tips);
Python
This approach uses the kernel density estimate to provide a richer description of the distribution of values. Additionally, the quartile and whisker values from the boxplot are shown inside the violin. The downside is that, because the violinplot uses a KDE, there are some other parameters that may need tweaking, adding some complexity relative to the straightforward boxplot:
바이올린 플롯은 커널 밀도 추정을 사용해 값들의 분포를 보다 수준 높게 묘사한다. 더군다나 수염상자그림에서 파생된 분위수 개념과 수염 개념도 바이올린 모양 안에서 구현된다.
( 역주 : 바이올린 플롯 내부를 잘 봐보면 굵은 선으로 IQR의 범위를, 얇은 선으로 박스플롯의 수염 부분이 포함하는 범위를 표현하고 있다)
다만 바이올린 플롯이 KDE (커널 밀도 추정) 를 쓰기 때문에 박스플롯을 바로 쓰는 것에 비해 불리한 부분이 있다. 다소 복잡하게 조정할 필요가 있는 인자와 매개변수들이 존재하다는 점이다.
sns.catplot(x="total_bill", y="day", hue="sex", kind="violin", bw=.15, cut=0, data=tips);
Python
It’s also possible to “split” the violins when the hue parameter has only two levels, which can allow for a more efficient use of space:
바이올린 모형을 hue 인자(hue="")와 그에 기입한 매개변수 (="sex")를 통해 의미 구분을 추가하되 "나누기 split" 가 가능하다. 단 그 구분이 2개일 때만 가능하고, 이는 공간 사용에 있어서 보다 효율적이다.
sns.catplot(x="day", y="total_bill", hue="sex", kind="violin", split=True, data=tips);
Python
Finally, there are several options for the plot that is drawn on the interior of the violins, including ways to show each individual observation instead of the summary boxplot values:
마지막으로, 바이올린 모양의 그림 속에 그려져 묘사되는 몇가지 옵션들을 소개한다. 이 방식은 박스플롯의 요약 방식 (뚱뚱함으로 분포를 표현하는 방식)과 달리 각각의 데이터를 직접 보여주는 걸 포함하고 있다.
sns.catplot(x="day", y="total_bill", hue="sex", kind="violin", inner="stick", split=True, palette="pastel", data=tips);
Python
It can also be useful to combine swarmplot() or striplot() with a box plot or violin plot to show each observation along with a summary of the distribution:
swarmplot() 혹은 striplot() 기법과 박스플롯 / 바이올린 플롯과 결합하는 것도 유용하다. 각각의 관찰값들을 두께로 표현한 분포 요약과 함께 보여주는 것이다.
g = sns.catplot(x="day", y="total_bill", kind="violin", inner=None, data=tips) sns.swarmplot(x="day", y="total_bill", color="k", size=3, data=tips, ax=g.ax);
Python

Statistical estimation within categories¶

범주형 데이터를 사용한 통계적 추정
For other applications, rather than showing the distribution within each category, you might want to show an estimate of the central tendency of the values. Seaborn has two main ways to show this information. Importantly, the basic API for these functions is identical to that for the ones discussed above.
각 범주에 소속한 데이터들의 분포를 보여주는 것과는 다르게, 데이터들의 주된 경향성를 보여주고 싶을 수도 있다. Seaborn에서는 이러한 정보를 보여주는 방식으로는 주로 두 가지 방식이 있다. 이러한 기능들의 기본이 되는 API가 위에서 봐왔던 것들과 동일하다는 것이 중요하다.

Bar plots

막대 그래프
A familiar style of plot that accomplishes this goal is a bar plot. In seaborn, the barplot() function operates on a full dataset and applies a function to obtain the estimate (taking the mean by default). When there are multiple observations in each category, it also uses bootstrapping to compute a confidence interval around the estimate, which is plotted using error bars:
경향성을 보여주는 가장 친숙한 스타일은 막대 그래프이다. Seaborn에서 barplot()은 모든 데이터셋에 걸쳐서 작동하며, 추정치를 얻는다 (기본적으로는 평균값을 계산한다). 각 범주마다 여러개의 관찰값이 있다면 (선 그래프와 마찬가지로) 부트스트래핑 기법을 써서 추정치로부터 신뢰구간을 계산한다. 그 값은 "오차 막대error bars"를 사용해 표현된다.
titanic = sns.load_dataset("titanic") sns.catplot(x="sex", y="survived", hue="class", kind="bar", data=titanic);
Python
A special case for the bar plot is when you want to show the number of observations in each category rather than computing a statistic for a second variable. This is similar to a histogram over a categorical, rather than quantitative, variable. In seaborn, it’s easy to do so with the countplot() function:
각 범주의 통계적 추정치를 계산하는 것보다는 단순히 관찰된 값을 보여주고 싶을 때가 있을 것이다. 막대 그래프 표현법에는 이러한 특별한 상황이 존재할 수 있으며, 이는 마치 전반적인 범주에 걸쳐서 히스토그램을 그리는 것과 비슷하다. Seaborn에서는 countplot() 기능을 통해 손쉽게 구현이 가능하다.
sns.catplot(x="deck", kind="count", palette="ch:.25", data=titanic);
Python
Both barplot() and countplot() can be invoked with all of the options discussed above, along with others that are demonstrated in the detailed documentation for each function:
barplot()countplot()은 모두 지금까지 배웠던 모든 옵션들 안에서 구현될 수 있다. 각각의 플롯들의 가이드(document) 안에서 자세히 설명된 내용들과 함께 사용하면 된다.
sns.catplot(y="deck", hue="class", kind="count", palette="pastel", edgecolor=".6", data=titanic);
Python

Point plots¶

점 그래프
An alternative style for visualizing the same information is offered by the pointplot() function. This function also encodes the value of the estimate with height on the other axis, but rather than showing a full bar, it plots the point estimate and confidence interval. Additionally, pointplot() connects points from the same hue category. This makes it easy to see how the main relationship is changing as a function of the hue semantic, because your eyes are quite good at picking up on differences of slopes
pointplot()은 동일한 데이터를 시각화를 하는 대안적인 방법론이다. 한 범주의 데이터가 갖는 추정치 (추정치의 기본 옵션은 평균값을 구하는 것이다 default = mean)를 다른 축의 값에 견주어 찍는 것이다. 막대를 이용해 표현하는 게 아니라 점과 신뢰구간만 찍는다. 그 상태에서 같은 hue로 이루어진 범주에 찍힌 점들을 잇는다. 이를 통해 hue로써 구분된 데이터들이 메인 카테고리가 변해감에 따라 어떻게 상관관계가 변해가는지를 쉽게 파악할 수 있다. 왜냐하면 우리의 시각이 기울기의 변화를 파악하는데 매우 탁월하기 때문이다.
( 역주 : "메인 카테고리가 변해감에 따라" 라는 말은 아래 예시에서 "sex" 카테고리가 남성에서 여성으로 바뀌는 것을 보면 쉽게 이해할 수 있다)
sns.catplot(x="sex", y="survived", hue="class", kind="point", data=titanic);
Python
While the categorical functions lack the style semantic of the relational functions, it can still be a good idea to vary the marker and/or linestyle along with the hue to make figures that are maximally accessible and reproduce well in black and white:
비록 범주형 데이터를 기반으로한 도표들이 style을 통한 의미구분하는 게 불가능하지만 (현재까지는 hue를 통한 의미구분만 가능하다), hue를 통한 의미구분을 해놓고 거기에 추가적으로 점이나 선의 모양까지 바꿔 놓는 건 여전히 매우 훌륭한 아이디어이다. 흑백 출력 상황에 대한 대비를 하면서 도표를 더 잘 이해하도록 만들기 때문이다.
sns.catplot(x="class", y="survived", hue="sex", palette={"male": "g", "female": "m"}, markers=["^", "o"], linestyles=["-", "--"], kind="point", data=titanic);
Python

Plotting “wide-form” data¶

"넓은 형식"의 데이터 도표
While using “long-form” or “tidy” data is preferred, these functions can also by applied to “wide-form” data in a variety of formats, including pandas DataFrames or two-dimensional numpy arrays. These objects should be passed directly to the data parameter:
"long-form (적은 칼럼 & 많은 로우 로 구성된 세로로 긴 데이터 구성)" 데이터나 전처리된 깔끔한 데이터들이 물론 선호되나, 지금까지 소개한 기능들은 "wide-form (칼럼수가 많은 형태)" 데이터에도 적용할 수 있다. 판다스 데이터 프레임이나 2차원 넘파이 arrays 를 포함한 다양한 데이터 포맷에도 적용 가능하다. seaborn 클래스가 data 인자에 파라미터로 넣은 기반 데이터를 파악하여 바로 구현한다.
iris = sns.load_dataset("iris") sns.catplot(data=iris, orient="h", kind="box");
Python
Additionally, the axes-level functions accept vectors of Pandas or numpy objects rather than variables in a DataFrame:
추가적으로, axes-level의 클래스들은 판다스와 넘파이의 객체 데이터를 바로 벡터로 삼을 수 있다. 데이터프레임을 굳이 이용하지 않고도 구현이 가능하다.
sns.violinplot(x=iris.species, y=iris.sepal_length);
Python
( 역주 : 위 예제 코드에서는 그 전 예시에서 썼듯이 data = 파라미터를 통해 데이터를 지정하는 게 아니라, iris.species 라는 판다스에 내장된 기본 연습 데이터 객체를 사용하고 있다.)
To control the size and shape of plots made by the functions discussed above, you must set up the figure yourself using matplotlib commands:
지금까지 배운 기능들로 만든 도표의 크기나 모양을 조절하려면 , (Seaborn의 기반 프로그램인) matplotlib 의 명령어를 이용해 직접 모양을 설정해 주어야 한다.
f, ax = plt.subplots(figsize=(7, 3)) sns.countplot(y="deck", data=titanic, color="c");
Python
This is the approach you should take when you need a categorical figure to happily coexist in a more complex figure with other kinds of plots.
이제 소개할 방법은, 당신이 범주에 따른 데이터 모양을 다른 종류의 그래프와 함께 사용해 복잡해진 꼴을 다룰 때 권고되는 방법이다. 이 방법은 범주형 데이터가 다른 그래프들과 잘 공존하려면 필수적으로 익혀야 한다고 본다.

Showing multiple relationships with facets¶

파셋facets 옵션을 사용해 여러 관계들 표현하기
Just like relplot(), the fact that catplot() is built on a FacetGrid means that it is easy to add faceting variables to visualize higher-dimensional relationships:
relplot()과 마찬가지로, catplot() 역시 FacetGrid 기능 기반으로 만들어졌다. 이는 고차원의 상관관계를 표현하기 위해 파셋facet 변수들을 추가하는 게 더 쉽다는 의미이기도 하다.
( 역주 : 파셋 그리드는 axes-level에 속하는 클래스이다. 파셋 그리드는 앞선 1장 튜토리얼에서도 배웠듯이 여러개의 서브셋 그래프를 그리는 기법이다.)
sns.catplot(x="day", y="total_bill", hue="smoker", col="time", aspect=.6, kind="swarm", data=tips);
Python
For further customization of the plot, you can use the methods on the FacetGrid object that it returns:
그래프 커스터마이징을 더 고도화하기 위해선, 아래와 같은 결과물을 이끌어내는 FacetGrid의 기법을 사용할 수 있다.
g = sns.catplot(x="fare", y="survived", row="class", kind="box", orient="h", height=1.5, aspect=4, data=titanic.query("fare > 0")) g.set(xscale="log");
Python
( 역주 : row="class" 라는 FacetGrid 파라미터를 통해 row 방향으로 "class"에 따른 의미구분을 두어 3개의 서브셋 그래프를 나눠 그렸다)