"Christlich Demokratische Union (CDU) im Wahlkreis 208 Neustadt - Speyer",
"CDU-Kreisverband Pinneberg",
"CDU Landesverband Berlin",
"CDU Kreisverband Kassel-Land",
"CDU Kreisverband Cuxhaven",
"CDU Stadtverband Schwalmstadt",
"CDU-Landesverband Baden-WÃ¼rttemberg",
"CDU Kreisverband Görlitz",
"Christlich Demokratische Union (CDU) Landesverband ThÃ¼ringen",
"CDU Landesverband Rheinland-Pfalz",
"CDU Kreisverband Main-Tauber",
"CDU Kreisverband Bremen-Nord",
"CDU Kreisverband Mainz",
"CDU Schwalm-Eder"
)
csu <- c(
"Christlich-Soziale Union Bayern eingetragener Verein",
"CSU"
)
fdp <- c(
"Freie Demokratische Partei (FDP), Landesverband Bayern eingetragener Verein",
"FDP Kreisverband Ravensburg",
"Freie Demokratische Partei",
"FDP Freiburg",
"Freie Demokratische Partei (FDP)",
"FDP Landesverband Saarland",
"FDP Kreisverband Bielefeld",
"Junge Liberale e.V.",
"FDP Kreisverband Bochum",
"FDP Kreisverband Speyer",
"FDP Oberallgäu",
"FDP Heidelberg",
"FDP Kreisverband Heidekreis",
"FDP Bayern Kreisverband MÃ¼nchen-Land Ortsverband (OV) GrÃ¼nwald",
"FDP Nürnberg",
"FDP Kreisverband Regensburg-Stadt"
)
fw <- c(
"FREIE WÄHLER Niedersachsen",
"Landesvereinigung FREIE WÄHLER Bayern e.V."
)
humanisten <- "Partei der Humanisten"
linke <- c(
"DIE LINKE. Mecklenburg-Vorpommern",
"DIE LINKE",
"DIE LINKE. Kreisverband Hildesheim",
"DIE LINKE Landesverband Berlin",
"Die Linke Hessen"
)
odp <- "Ökologisch-Demokratische Partei (ÖDP)"
piraten <- c(
"Piratenpartei Deutschland",
"Piratenpartei Deutschland Landesverband Hessen"
)
sgp <- "Sozialistische Gleichheitspartei (SGP)"
spd <- c(
"Sozialdemokratische Partei Deutschlands (SPD) SPD Ortsverein Neu Wulmstorf",
"Sozialdemokratische Partei Deutschlands SPD",
"Sozialdemokratische Partei Deutschlands Unterbezirk Bonn",
"Sozialdemokratische Partei Deutschlands, Landesverband Berlin",
"SPD-Kreisverband Rastatt/Baden-Baden",
"SPD-Ortsverein Uelzen",
"SPD-UB Landkreis Harburg",
"SPD-Unterbezirk Aachen-Stadt",
"SPD-Unterbezirk Coesfeld",
"SPD-Unterbezirk Main-Taunus",
"SPD Baden-Württemberg",
"SPD Eimsbüttel",
"SPD Kreisverband Gütersloh",
"SPD Kreisverband Warendorf",
"SPD Landesorganisation Hamburg",
"SPD Mecklenburg Vorpommern",
"SPD Ortsverein Augustfehn",
"SPD Ortsverein Löningen",
"SPD Ortsverein Uchte",
"SPD Osnabrück",
"SPD Rhein-Neckar",
"SPD Schwalm-Eder"
)
tierschutz <- "PARTEI MENSCH UMWELT TIERSCHUTZ (Tierschutzpartei)"
volt <- "Volt Deutschland"
df <- df |>
mutate(advertiser = case_when(
Advertiser_Name %in% spd ~ 1,
Advertiser_Name %in% cdu ~ 2,
Advertiser_Name %in% csu ~ 3,
Advertiser_Name %in% b90 ~ 4,
Advertiser_Name %in% afd ~ 5,
Advertiser_Name %in% fdp ~ 6,
Advertiser_Name %in% linke ~ 7,
Advertiser_Name %in% fw ~ 8,
Advertiser_Name %in% odp ~ 9,
Advertiser_Name %in% tierschutz ~ 10,
Advertiser_Name %in% piraten ~ 11,
Advertiser_Name %in% humanisten ~ 12,
Advertiser_Name %in% buc ~ 13,
Advertiser_Name %in% volt ~ 14,
Advertiser_Name %in% sgp ~ 15,
TRUE ~ NA
))
table(df$advertiser)
############
#Recode Ad type
library(dplyr)
df <- df |>
mutate(Ad_Type_num = as.numeric(factor(Ad_Type)))
table(df$Ad_Type_num)
detach("package:dplyr", unload = TRUE)
#Package ggplot; version: 3.5.1; full documentation: https://ggplot2.tidyverse.org/
library(ggplot2)
# Create a data frame
df.plot <- data.frame(
category = c("SPD", "CDU", "CSU", "Greens", "AfD", "FDP", "Left", "FW", "ÖDP", "Tierschutz", "Pirates", "Humanists", "BUC", "Volt", "SGP"),
values = c(374, 301, 35, 185, 2494, 1257, 76, 17, 38, 30, 9, 3, 8, 299, 3)
)
#Prepare category for plotting (factor maintains order)
df.plot$category <- factor(df.plot$category, levels = df.plot$category)
# Create the bar plot
ggplot(df.plot, aes(x = category, y = values)) +
geom_bar(stat = "identity", fill = "darkslategray") +
labs(title = "Parties advertising via Google services", x = "Party", y = "N of Ads") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
detach("package:ggplot2", unload = TRUE)
library(dplyr)
df <- df |>
mutate(advertiser_reduced = case_when(
Advertiser_Name %in% spd ~ 1,
Advertiser_Name %in% cdu ~ 2,
Advertiser_Name %in% csu ~ 3,
Advertiser_Name %in% b90 ~ 4,
Advertiser_Name %in% afd ~ 5,
Advertiser_Name %in% fdp ~ 6,
Advertiser_Name %in% linke ~ 7,
Advertiser_Name %in% volt ~ 14,
TRUE ~ NA
),
advertiser_label = factor(case_when(
advertiser_reduced == 1 ~ "SPD",
advertiser_reduced == 2 ~ "CDU",
advertiser_reduced == 3 ~ "CSU",
advertiser_reduced == 4 ~ "Greens",
advertiser_reduced == 5 ~ "AfD",
advertiser_reduced == 6 ~ "FDP",
advertiser_reduced == 7 ~ "Left",
advertiser_reduced == 14 ~ "Volt",
TRUE ~ "Other"
), levels = c("SPD", "CDU", "CSU", "Greens", "AfD", "FDP", "Left", "Volt", "Other")))
table(df$advertiser_label)
table01 <- table(df$Ad_Type_num, df$advertiser_label)
print(table01)
table(df$advertiser)
library(ggplot2)
#Package reshape 2; version: 1.4.4, full documentation: https://github.com/hadley/reshape
library(reshape2)
# Create a data frame
matrix1 <- matrix(c(108, 42, 18, 83, 2191, 493, 21, 122,
105, 48, 5, 81, 4, 433, 19, 31,
161, 211, 12, 21, 299, 331, 36, 146),
ncol = 8, byrow = TRUE)
rownames(matrix1) <- c("Image", "Text", "Video")
colnames (matrix1) <- c("SPD (n=374)", "CDU (n=301)", "CSU (n=35)", "Greens (n=185)", "AfD (n=2494)", "FDP (n=1257)", "Left (n=76)", "Volt (n=299)")
# calculating percentages per column
prop_data <- prop.table(matrix1, margin =2)
print(prop_data)
# DataFrame for ggplot2
df.plot01 <- as.data.frame(prop_data)
df.plot01$category <-rownames(df.plot01)
df_melted <- melt(df.plot01, id.vars = "category")
