In [ ]:
from dsc106_utils import *
In [ ]:
mpg = sns.load_dataset('mpg').dropna()
mpg
In [ ]:
mpg['origin'].value_counts().reset_index()
Nimble design moves¶
In [ ]:
px.bar(
mpg['origin'].value_counts().reset_index(),
x='origin',
y='count',
)
In [ ]:
In [ ]:
In [ ]:
1 Nominal, 1 Quantitative¶
In [ ]:
px.bar(
mpg['origin'].value_counts().reset_index(),
x='origin',
y='count',
)
In [ ]:
In [ ]:
Encoding 3 variables¶
In [ ]:
px.scatter(
mpg,
x='horsepower',
y='mpg',
)
In [ ]:
In [ ]:
In [ ]:
occ = mpg.groupby(['origin', 'cylinders']).size().rename('count').reset_index()
occ
In [ ]:
px.bar(
occ,
x='count',
y='origin',
color='cylinders',
)
In [ ]:
omc = mpg.groupby(['origin', 'model_year']).size().rename('count').reset_index()
omc
In [ ]:
px.line(
omc,
x='model_year',
y='count',
color='origin'
)
What about 4 channels?¶
In [ ]:
mpg
In [ ]:
means = (mpg
.groupby(['origin', 'model_year'])
['mpg']
.max()
.reset_index()
)
means
In [ ]:
px.scatter(
means,
x='model_year',
y='origin',
color='origin', # redundant encoding!
size='mpg',
)