-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (70 loc) · 3.04 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
---
title: "Nationalratswahlen Kanton Thurgau: Parteistärken nach Gemeinden"
author: "OGD-Koordinationsstelle Kanton Thurgau"
date: "`r Sys.Date()`"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Open Government Data, provided by **Canton Thurgau**
*Autogenerated R starter code for dataset with the identifier* **sk-stat-123**
# **Nationalratswahlen Kanton Thurgau: Parteistärken nach Gemeinden**
[Link to dataset on data.tg.ch](https://data.tg.ch/explore/dataset/sk-stat-123/information/)
## Description
<p>Dieser Dataset präsentiert die Ergebnisse der Nationalratswahlen für den Kanton Thurgau (Parteistimmen, Parteistärke) nach Bezirk, Gemeinde und Partei, ab 1971.</p><p>Datenquelle: Bundesamt für Statistik BFS / Staatskanzlei Kanton Thurgau (2023)</p><p>Link zur PX-Tabelle: https://www.bfs.admin.ch/asset/de/px-x-1702020000_105</p><p><br/></p><p><br/></p>
## Metadata
- **Issued** :
- **Modified** : 2024-11-01 08:56:35
- **Rights** : CC BY 4.0
- **Keywords** : Politik, politik, Wahlen , parteistimmen, parteistarke, Partei , parteien, parlament, Nationalrat, Nationalratswahlen, svp, cvp, glp, gp, mitte, fdp
## Load Packages
Every dataset (csv and geodata) on [data.tg.ch](https://data.tg.ch/pages/start/) can be retrieved with the **tgAPI** package. You can download it via [GitHub](https://github.com/ogdtg/tgAPI). Please note that the package has some dependencies, which can result in a lengthy installation process. Therefore, we do not recommend installing the package directly in Google Colab. However, if you intend to run this code on your local machine, we strongly recommend installing the tgAPI package.
```{r}
library(httr)
library(jsonlite)
library(dplyr)
# library(remotes)
# remotes::install.github("ogdtg/tgAPI")
```
## Download Data
```{r}
# Download the Dataset via API
res <- httr::GET("https://data.tg.ch/api/explore/v2.0/catalog/datasets/sk-stat-123/exports/json")
data <- res$content %>%
rawToChar() %>%
jsonlite::fromJSON()
# Use tgAPI
# data <- tgAPI::get_dataset("sk-stat-123")
head(data)
```
## Explore Metadata
```{r}
res <- httr::GET("https://data.tg.ch/api/explore/v2.0/catalog/datasets/sk-stat-123")
metadata <- res$content %>%
rawToChar() %>%
jsonlite::fromJSON()
# Fields name
cat("\nFields name")
metadata$dataset$fields$name
# Fields description
cat("\nFields description")
metadata$dataset$fields$description
# Fields data type
cat("\nFields data type")
metadata$dataset$fields$type
```
## Analyze data
```{r}
# Look at the dataset and its structure
summary(data)
```
## Continue your code here...
```{r}
# Do some data magic with R
```
------------------------------------------------------------------------
## Questions about the data?
Contact us via [Mail](mailto:[email protected]) or visit our [GitHub presence](https://github.com/ogdtg)
------------------------------------------------------------------------
OGD-Koordinationsstelle Kanton Thurgau | Grabenstrasse 8 | 8510 Frauenfeld