Created
January 26, 2024 10:04
-
-
Save JanMarvin/c1dfcf699cbb260326d71154486ecbb3 to your computer and use it in GitHub Desktop.
Voting trend in spreadsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
url <- "https://www.garbuszus.de/marvin/wahlumfragen_raw.csv" | |
dat <- read.csv2(url) | |
dat$date <- as.Date(dat$date) | |
nms <- names(dat) | |
nms[nms == "CDU.CSU"] <- "CDU/CSU" | |
names(dat) <- nms | |
library(openxlsx2) | |
wb <- wb_workbook()$ | |
add_chartsheet("chart")$ | |
add_worksheet("data")$ | |
add_data(x = dat) | |
# create wb_data object this will tell this mschart | |
# from this PR to create a file corresponding to openxlsx2 | |
dat <- wb_data(wb, rows = seq_len(nrow(dat)), cols = seq_len(8)) | |
# create a few mscharts | |
chrt <- dat |> | |
mschart::ms_linechart( | |
x = "date", | |
y = names(dat)[-1] | |
) |> | |
mschart::chart_ax_x( | |
num_fmt = "yyyy-mm-dd" | |
) |> | |
mschart::chart_labels( | |
title = "German Voting Trends. \n'Who would you vote for, if next sunday was general election?' (Sonntagsfrage)", | |
xlab = "Time", | |
ylab = "in %" | |
) |> | |
mschart::chart_data_stroke( | |
values = c( | |
`CDU/CSU` = "#000000", | |
SPD = "#EB001F", | |
`GRÜNE` = "#64A12D", | |
FDP = "#FFED00", | |
LINKE = "#BE3075", | |
AfD = "#009EE0", | |
Sonstige = "#FF820A" | |
) | |
) |> | |
mschart::chart_settings(style = "line") | |
wb$add_mschart(sheet = "chart", graph = chrt) | |
if (interactive()) wb$open() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment