Skip to content

Instantly share code, notes, and snippets.

@HeidiSeibold
Created August 29, 2018 09:37
Show Gist options
  • Save HeidiSeibold/03e66c46fd495e7725193cbc24f36831 to your computer and use it in GitHub Desktop.
Save HeidiSeibold/03e66c46fd495e7725193cbc24f36831 to your computer and use it in GitHub Desktop.
library("googlesheets")
library("dplyr")
library("readr")
#" - If not done yet: Run `gs_auth()` in R
#" - Go to https://docs.google.com/spreadsheets/d/1XOfLLmd4h676vCBoVy8qtIjYvkyFDDkLwW_OASFjoMg
#" - In the spreadsheet click "Add to my drive"
#" - Open spreadsheet in your drive
#" - Get title
sheet <- gs_title("diesel-geht-die-luft-aus")
nzw <- sheet %>% gs_read(ws = 1, col_types = cols(
Datum = col_date("%Y-%m"),
Gesamt = col_double(),
Diesel = col_double(),
`Anderer Antrieb gesamt` = col_double(),
Benzin = col_double(),
Hybrid = col_double(),
Elektro = col_double(),
Erdgas = col_double(),
Flüssiggas = col_integer(),
`Anteil Benzin` = col_number(),
`Anteil Diesel` = col_number(),
`Anteil Elektro und Hybrid` = col_number(),
`Anteil Gas und Sonstige` = col_number()
))
library("ggplot2")
library("reshape2")
nzp <- melt(nzw, id.vars = c("Datum"),
measure.vars = c("Anteil Diesel", "Anteil Benzin",
"Anteil Elektro und Hybrid", "Anteil Gas und Sonstige"),
variable.name = "Typ",
value.name = "Anteil")
ggplot(nzp, aes(x = Datum, y = Anteil, color = Typ, group = Typ)) +
geom_line()
nz <- melt(nzw, id.vars = c("Datum"),
measure.vars = c("Diesel", "Anderer Antrieb gesamt", "Benzin", "Hybrid",
"Elektro", "Erdgas", "Flüssiggas"),
variable.name = "Typ",
value.name = "Anzahl")
ggplot(nz, aes(x = Datum, y = Anzahl, color = Typ, group = Typ)) +
geom_line()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment