1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
---
title: "Altair Example"
output:
html_document:
df_print: paged
pdf_document: default
---
```{r}
library(reticulate)
# py_install(c("altair", "vega_datasets", "pandas"))
```
```{python, altair.fig.width=800, altair.fig.height=300}
import altair as alt
from vega_datasets import data
source = data.movies.url
alt.Chart(source).mark_bar().encode(
alt.X("IMDB_Rating:Q", bin=True),
y='count()',
)
```
## Compound charts
```{python}
import altair as alt
import pandas as pd
source = pd.DataFrame({
'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],
'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]
})
fig1 = alt.Chart(source).mark_bar().encode(
x='a',
y='b'
)
fig2 = alt.Chart(source).mark_bar().encode(
x='a',
y='b',
color='b:N'
)
fig3 = alt.Chart(source).mark_bar().encode(
x='a',
y='b',
color='a:N'
)
```
## Compound Chart1
```{python}
#| label: first
(fig1 | fig2).properties(title="This is the First Chart")
```
## Compound Chart2
```{python}
#| label: second
(fig2 | fig1).properties(title="This is the Second Chart")
```
## Compound Chart3
```{python}
#| label: third
(fig2 | fig1 | fig3).properties(title="This is the Third Chart")
```
|