Skip to content

Commit 68b4980

Browse files
committed
Merged changes Danai
1 parent fc103df commit 68b4980

File tree

6 files changed

+21
-16
lines changed

6 files changed

+21
-16
lines changed

pages/vega-in-r/brush-and-link.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ series: vega-in-r-series
88
weight: 10
99
---
1010

11-
We have seen how to concatenate charts, we may now see how to connect them interactively.
12-
- To do so, we first create a static chart using the step 1 of the code below.
11+
We have seen how to concatenate charts, we may now see how to connect them interactively. The steps described here are based on the [Interactive Examples article](https://vegawidget.github.io/altair/articles/interactive.html).
12+
- To get started, we create a static chart using the step 1 of the code below.
1313
- The second step is to add a selection. Here we add a selection of type `interval` but a selection can also be `single` or `multi` [altair.selection reference](https://altair-viz.github.io/user_guide/generated/api/altair.selection.html?highlight=selection#altair.selection). In step 2, we also name the selection 'brush' and we update the static chart by including the selection function.
1414
- Finally, in step 3, we update the color encoding of the data, so that every time the chart is brused the data inside the selection are colored, based on the nominal variable `Missing`, and the rest are colored lightgray.
1515

pages/vega-in-r/changing-data.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ weight: 3
99
---
1010
Let's now use a more realistic example and visualize a dataset included in the `vega_datasets` package [https://github.com/vega/vega-datasets.html](https://github.com/vega/vega-datasets.html).
1111

12-
You can import the vega datasets using the altair library.
12+
We can import the vega datasets using the altair library.
1313
```R
1414
vega_data = altair::import_vega_data()
1515
```
1616

17-
See the list of the available datasets
17+
Check out the list of the available datasets:
1818
```R
1919
vega_data$list_datasets()
2020
```
@@ -71,7 +71,7 @@ head(data_source); tail(data_source)
7171
```
7272

7373
We can now make an altair R plot similar to the one at altair Python [https://altair-viz.github.io/gallery/natural_disasters.html](https://altair-viz.github.io/gallery/natural_disasters.html)
74-
For now, we may filter the data in R and use the subset of the data to make the chart. On the data transform section we will see how to do the filtering inside the altair chart specification.
74+
For now, we may filter the data in R and use the subset of the data to make the chart. On the data transform section we will see how to do the filtering inside the chart specification.
7575

7676
<br/>
7777

@@ -140,7 +140,7 @@ chart_disasters = alt$Chart(data_source_subset)$
140140
width=500
141141
)
142142
```
143-
The global properties of the circles are specified inside the mark attribute and the properties that depend on the data inside the encoding.
143+
Here, the global properties of the circles are specified inside the mark attribute while the properties that depend on the data inside the encoding.
144144
Using the mark type `rect` with `color` and `opacity` channels we can make a heatmap plot.
145145

146146

pages/vega-in-r/data-transformations.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ series: vega-in-r-series
88
weight: 6
99
---
1010

11-
As mentioned in the documentation of altair, [https://altair-viz.github.io/user_guide/transform/index.html](https://altair-viz.github.io/user_guide/transform/index.html) in most cases, it is suggested to perform transformations outside the chart definition, so in our case using R. Of course, data transforms inside the chart can also be useful in some cases.
12-
So far, we have been filtering the data in R and then using the modified data in the chart specification. Now, we use the `transform_filter()` to subset the data inside the chart. We make the linechart we have seen in a previous section using the code below:
11+
As mentioned in the [data transformations documentation](https://altair-viz.github.io/user_guide/transform/index.html) of altair, in most cases, it is suggested to perform transformations outside the chart definition, so in our case using R. Of course, data transforms inside the chart can also be useful in some cases.
12+
So far, we have been filtering the data in R and then using the modified data in the chart specification. Now, we use the `transform_filter()` to subset the data inside the chart. [Here](https://altair-viz.github.io/user_guide/transform/filter.html#user-guide-filter-transform) is the filter transfrom documentation. We make the linechart we have seen in a previous section using the code below:
1313

1414
```R
1515
chart_disasters = alt$Chart("https://raw.githubusercontent.com/vega/vega-datasets/master/data/disasters.csv")$
@@ -121,7 +121,7 @@ We use the field predicates to assess whether a data point satisfied certain con
121121

122122
<br/>
123123

124-
We now also use the `transform_window()` for data transformation to compute and plot a windowed aggregation of the deaths over all available years.
124+
We now also use the `transform_window()` for data transformation to compute and plot a windowed aggregation of the deaths over all available years. [Here](https://altair-viz.github.io/user_guide/transform/window.html#user-guide-window-transform) is the window transform documentation.
125125

126126

127127
```R

pages/vega-in-r/layered-chart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ series: vega-in-r-series
88
weight: 7
99
---
1010

11-
We are now looking at how we can combine charts in one canvas in altair R.
11+
We are now looking at how we can combine charts in one canvas in altair R. This section on how to combine charts, is based on the [View Composition article](https://vegawidget.github.io/altair/articles/view-composition.html).
1212

1313
First, we are discussing a layered chart example. Each chart can be made separately and combined uisng the `+` operator: `chart_layer_1 + chart_layer_2`.
1414
Below, we make a chart that consists of a line layer and a point layer. The tooltip should be added to the top layer so that it is visible in the final chart.

pages/vega-in-r/setting-things-up.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ weight: 1
99
---
1010

1111
To get this tutorial started, we need, first, to install anaconda, and second, activate an r-reticulate environment using conda. We also need to install vega_datasets using pip and finally, install the R packages reticulate and altair using install.packages() in Rstudio.
12-
Most of the steps described here are taken from [altair R installation](https://vegawidget.github.io/altair/articles/installation.html).
12+
Most of the steps described here are taken from [altair R installation](https://vegawidget.github.io/altair/articles/installation.html). Make sure you are using Python version 3.5 or higher to comply to the system requirements of the altair R package [altair CRAN](https://cran.r-project.org/web/packages/altair/altair.pdf).
1313

14-
After installing Anaconda, open the Anaconda Prompt. Update conda:
14+
First, [install Anaconda](https://www.anaconda.com/distribution/) and after installing Anaconda, open the Anaconda Prompt.
15+
Update conda:
1516
``` C
1617
conda -V
1718
conda update conda
@@ -49,6 +50,8 @@ Verify the installation using:
4950
altair::check_altair()
5051
```
5152

53+
If there is no error on the verification, we are ready to start!
54+
<br/>
5255
The procedure described above should be run only in the beginning. The following times you want to use altair in Rstudio, you only need to call `library("altair")`.
5356

5457

pages/vega-in-r/simple-barchart.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Here is a very simple barchart defined in altair R.
7171
The dataset used for this chart is:
7272

7373
```R
74-
Var1 = c("a","b","c","d","e")
74+
Var1 = c("a","b","c","d","e")
7575
Var2 = c(11, 19, 22, 8, 14)
7676
Var3 = c("type1","type1","type2","type1","type2")
7777
dataset = data.frame(Var1, Var2, Var3)
@@ -93,14 +93,16 @@ chart_1 = alt$Chart(dataset)$
9393
)
9494
```
9595

96-
What is the syntax in altair R? It is similar to the altair Python with the major difference the usage of the operator `$` to access attributes, instead of `.`. We should note that there are some other differences of the Python and the R package described at the [Field Guide to Python Issues](https://vegawidget.github.io/altair/articles/field-guide-python.html) together with examples.
97-
We should also notice that we use the object `alt` to access the Altair API and create a chart using `alt$Chart`.
96+
What is the syntax in altair R? It is similar to the altair Python with the major difference the usage of the operator `$` to access attributes, instead of `.`. We should note that there are some other differences of the Python and the R package described at the [Field Guide to Python Issues](https://vegawidget.github.io/altair/articles/field-guide-python.html) together with examples. Below, are the most common properties of the chart syntax:
97+
- We first need to use the object `alt` to access the Altair API and create a chart using `alt$Chart`.
9898
- The `data` to be visualised is called inside the `alt$Chart`.
9999
- The `mark` used is specifed after `mark_`. Values as properties of the marks, for instance a hard-coded size or color, can be specified here.
100100
- The `encode` determines the mapping between the channels and the data fields. The encoding that is dependent on the fields is specified here, not the encoding that has to do with values of the marks. Here, `x` and `y` are the position channels. The field type is specified after the field name. `O` stands for ordinal and `Q` for quantitative. Other types are `N` for nominal, `T` for temporal and `G` for goejson. The `x = "Var1:O"` is the short form of `x = alt$X("Var1", type = "ordinal")`. The two forms are equivalent but the long form is used when doing more adjustments unside encoding. We will see an example in the field transform section.
101101
- The height and width of the plot is specified inside `properties`.
102102

103-
To display the chart in Rstudio `vegawidget(chart_1)` or `chart_1` will not work. We can instead save the chart using:
103+
For more detailed references in Altair classes and functions, we may look to the [API reference](https://altair-viz.github.io/user_guide/API.html).
104+
105+
Now, to display the chart in Rstudio we may use `vegawidget(chart_1)` or `chart_1`. Alternatively, we can also save the chart using:
104106
```R
105107
htmlwidgets::saveWidget(vegawidget(chart_1),'chart_1.html')
106108
```

0 commit comments

Comments
 (0)