source("Global_Libraries.R")
## Perform Analysis for Article
# Call Modul for re-reading of Main Data, in case it has not been done before
source("Global_Libraries.R")
source("Modul_CalculateData.R")
## Perform Analysis for Article
# Call Modul for re-reading of Main Data, in case it has not been done before
source("Scripts/Global_Libraries.R")
source("Scripts/Modul_CalculateData.R")
## Perform Analysis for Article
# Call Modul for re-reading of Main Data, in case it has not been done before
source("Scripts/Global_Libraries.R")
source("Scripts/Modul_CalculateData.R")
## Perform Analysis for Article
# Call Modul for re-reading of Main Data, in case it has not been done before
source("Scripts/Global_Libraries.R")
source("Scripts/Modul_CalculateData.R")
source("Scripts/Global_Libraries.R")
source("Scripts/Modul_CalculateData.R")
source("Scripts/Global_Variables.R")
## Perform Analysis for Article
# Call Modul for re-reading of Main Data, in case it has not been done before
source("Scripts/Global_Libraries.R")
source("Scripts/Modul_CalculateData.R")
#source("Scripts/Global_Variables.R")
# Call libraries used just for this analysis
library(corrplot)
## Get tables and plot for all correlations
# Loop gets data for internal / external variables (in "Names") and cor-Plots with all of them. Also produces tables for all data / years
# Funtion to get cor-plots
fun_cor <- function(group_name, variables){
for (i in Years){
temp <- Main_Data %>% select(`Library ID`)
for (j in variables) {
temp2 <- Main_Data %>% select((paste0(j, " ", i)))
temp <- cbind(temp, temp2)
}
temp <- temp[ , -1]
temp[is.na(temp)] <- 0
assign(paste0("analysis_data_", i), as.data.frame(temp))
temp <- cor(temp)
assign(paste0("analysis_cor", i), temp)
png(file=paste0("Analysis 1/Plots/Correlations/", group_name, "__", "cor_numbers_", i, ".png"), width=1000, height = 1000)
corrplot(temp, method = "number", col=colorRampPalette(c("red3", "gold2", "olivedrab"))(600))
dev.off()
png(file=paste0("Analysis 1/Plots/Correlations/", group_name, "__", "cor_rounds_", i, ".png"), width=700, height = 700)
# corrplot(temp, col=COL1("Oranges"))
corrplot(temp, col=colorRampPalette(c("red3", "gold2", "olivedrab"))(600))
dev.off()
png(file=paste0("Analysis 1/Plots/Correlations/", group_name, "__", "cor_FPC_", i, ".png"), width=700, height = 700)
corrplot(temp, method = 'square', order = 'FPC', type = 'lower', diag = FALSE, col=colorRampPalette(c("red3", "gold2", "olivedrab"))(600))
dev.off()
}
}
# Names and data for the investigated variables: (a) frist position must be the name of the group, (b) positions after that names of variables, (c) the group must be named in the "Gruppen"-list
alle <- c("all", "Number visits", "Users", "Permanent staff", "Permanent staff percentages", "Volunteer staff", "Opening hours per week", "Budget", "Media budget", "Collection physical", "Collection digital", "Seats", "Number events", "Number of loans", "Usage of ebooks", "Visitors events", "Budget per Inhabitant", "Percent Active Users")
internal <- c("interne_variablen", "Permanent staff", "Permanent staff percentages", "Volunteer staff", "Opening hours per week", "Collection physical", "Collection digital", "Seats", "Number events", "Number visits", "Users", "Number of loans", "Usage of ebooks", "Visitors events", "Percent Active Users")
external <- c("externe_variablen", "Budget", "Media budget", "Budget per Inhabitant", "Number visits", "Users", "Number of loans", "Usage of ebooks", "Visitors events", "Percent Active Users")
Gruppen <- c("alle", "internal", "external")
# run cor-function for all groups named in "Gruppen"
for (i in Gruppen) {
group_name <- get(i)[1]
var_names <- get(i)[-1]
fun_cor(group_name, var_names)
}
# Loop gets data for internal / external variables (in "Names") and cor-Plots with all of them. Also produces tables for all data / years
# Funtion to get cor-plots
fun_cor <- function(group_name, variables){
for (i in Years){
temp <- Main_Data %>% select(`Library ID`)
for (j in variables) {
temp2 <- Main_Data %>% select((paste0(j, " ", i)))
temp <- cbind(temp, temp2)
}
temp <- temp[ , -1]
temp[is.na(temp)] <- 0
assign(paste0("analysis_data_", i), as.data.frame(temp))
temp <- cor(temp)
assign(paste0("analysis_cor", i), temp)
png(file=paste0("Daten/Plots/Correlations/", group_name, "__", "cor_numbers_", i, ".png"), width=1000, height = 1000)
corrplot(temp, method = "number", col=colorRampPalette(c("red3", "gold2", "olivedrab"))(600))
dev.off()
png(file=paste0("Daten/Plots/Correlations/", group_name, "__", "cor_rounds_", i, ".png"), width=700, height = 700)
# corrplot(temp, col=COL1("Oranges"))
corrplot(temp, col=colorRampPalette(c("red3", "gold2", "olivedrab"))(600))
dev.off()
png(file=paste0("Daten/Plots/Correlations/", group_name, "__", "cor_FPC_", i, ".png"), width=700, height = 700)
corrplot(temp, method = 'square', order = 'FPC', type = 'lower', diag = FALSE, col=colorRampPalette(c("red3", "gold2", "olivedrab"))(600))
dev.off()
}
}
# Names and data for the investigated variables: (a) frist position must be the name of the group, (b) positions after that names of variables, (c) the group must be named in the "Gruppen"-list
alle <- c("all", "Number visits", "Users", "Permanent staff", "Permanent staff percentages", "Volunteer staff", "Opening hours per week", "Budget", "Media budget", "Collection physical", "Collection digital", "Seats", "Number events", "Number of loans", "Usage of ebooks", "Visitors events", "Budget per Inhabitant", "Percent Active Users")
internal <- c("interne_variablen", "Permanent staff", "Permanent staff percentages", "Volunteer staff", "Opening hours per week", "Collection physical", "Collection digital", "Seats", "Number events", "Number visits", "Users", "Number of loans", "Usage of ebooks", "Visitors events", "Percent Active Users")
external <- c("externe_variablen", "Budget", "Media budget", "Budget per Inhabitant", "Number visits", "Users", "Number of loans", "Usage of ebooks", "Visitors events", "Percent Active Users")
Gruppen <- c("alle", "internal", "external")
# run cor-function for all groups named in "Gruppen"
for (i in Gruppen) {
group_name <- get(i)[1]
var_names <- get(i)[-1]
fun_cor(group_name, var_names)
}
# Loop gets data for internal / external variables (in "Names") and cor-Plots with all of them. Also produces tables for all data / years
# Funtion to get cor-plots
fun_cor <- function(group_name, variables){
for (i in Years){
temp <- Main_Data %>% select(`Library ID`)
for (j in variables) {
temp2 <- Main_Data %>% select((paste0(j, " ", i)))
temp <- cbind(temp, temp2)
}
temp <- temp[ , -1]
temp[is.na(temp)] <- 0
assign(paste0("analysis_data_", i), as.data.frame(temp))
temp <- cor(temp)
assign(paste0("analysis_cor", i), temp)
png(file=paste0("Plots/Correlations/", group_name, "__", "cor_numbers_", i, ".png"), width=1000, height = 1000)
corrplot(temp, method = "number", col=colorRampPalette(c("red3", "gold2", "olivedrab"))(600))
dev.off()
png(file=paste0("Plots/Correlations/", group_name, "__", "cor_rounds_", i, ".png"), width=700, height = 700)
# corrplot(temp, col=COL1("Oranges"))
corrplot(temp, col=colorRampPalette(c("red3", "gold2", "olivedrab"))(600))
dev.off()
png(file=paste0("Plots/Correlations/", group_name, "__", "cor_FPC_", i, ".png"), width=700, height = 700)
corrplot(temp, method = 'square', order = 'FPC', type = 'lower', diag = FALSE, col=colorRampPalette(c("red3", "gold2", "olivedrab"))(600))
dev.off()
}
}
# Names and data for the investigated variables: (a) frist position must be the name of the group, (b) positions after that names of variables, (c) the group must be named in the "Gruppen"-list
alle <- c("all", "Number visits", "Users", "Permanent staff", "Permanent staff percentages", "Volunteer staff", "Opening hours per week", "Budget", "Media budget", "Collection physical", "Collection digital", "Seats", "Number events", "Number of loans", "Usage of ebooks", "Visitors events", "Budget per Inhabitant", "Percent Active Users")
internal <- c("interne_variablen", "Permanent staff", "Permanent staff percentages", "Volunteer staff", "Opening hours per week", "Collection physical", "Collection digital", "Seats", "Number events", "Number visits", "Users", "Number of loans", "Usage of ebooks", "Visitors events", "Percent Active Users")
external <- c("externe_variablen", "Budget", "Media budget", "Budget per Inhabitant", "Number visits", "Users", "Number of loans", "Usage of ebooks", "Visitors events", "Percent Active Users")
Gruppen <- c("alle", "internal", "external")
# run cor-function for all groups named in "Gruppen"
for (i in Gruppen) {
group_name <- get(i)[1]
var_names <- get(i)[-1]
fun_cor(group_name, var_names)
}
## Perform Analysis for Article
# Call Modul for re-reading of Main Data, in case it has not been done before
source("Scripts/Global_Libraries.R")
source("Scripts/Modul_CalculateData.R")
# Call libraries used just for this analysis
library(corrplot)
## Get tables and plot for all correlations
# Loop gets data for internal / external variables (in "Names") and cor-Plots with all of them. Also produces tables for all data / years
# Funtion to get cor-plots
fun_cor <- function(group_name, variables){
for (i in Years){
temp <- Main_Data %>% select(`Library ID`)
for (j in variables) {
temp2 <- Main_Data %>% select((paste0(j, " ", i)))
temp <- cbind(temp, temp2)
}
temp <- temp[ , -1]
temp[is.na(temp)] <- 0
assign(paste0("analysis_data_", i), as.data.frame(temp))
temp <- cor(temp)
assign(paste0("analysis_cor", i), temp)
png(file=paste0("Plots/Correlations/", group_name, "__", "cor_numbers_", i, ".png"), width=1000, height = 1000)
corrplot(temp, method = "number", col=colorRampPalette(c("red3", "gold2", "olivedrab"))(600))
dev.off()
png(file=paste0("Plots/Correlations/", group_name, "__", "cor_rounds_", i, ".png"), width=700, height = 700)
# corrplot(temp, col=COL1("Oranges"))
corrplot(temp, col=colorRampPalette(c("red3", "gold2", "olivedrab"))(600))
dev.off()
png(file=paste0("Plots/Correlations/", group_name, "__", "cor_FPC_", i, ".png"), width=700, height = 700)
corrplot(temp, method = 'square', order = 'FPC', type = 'lower', diag = FALSE, col=colorRampPalette(c("red3", "gold2", "olivedrab"))(600))
dev.off()
}
}
# Names and data for the investigated variables: (a) frist position must be the name of the group, (b) positions after that names of variables, (c) the group must be named in the "Gruppen"-list
alle <- c("all", "Number visits", "Users", "Permanent staff", "Permanent staff percentages", "Volunteer staff", "Opening hours per week", "Budget", "Media budget", "Collection physical", "Collection digital", "Seats", "Number events", "Number of loans", "Usage of ebooks", "Visitors events", "Budget per Inhabitant", "Percent Active Users")
internal <- c("interne_variablen", "Permanent staff", "Permanent staff percentages", "Volunteer staff", "Opening hours per week", "Collection physical", "Collection digital", "Seats", "Number events", "Number visits", "Users", "Number of loans", "Usage of ebooks", "Visitors events", "Percent Active Users")
external <- c("externe_variablen", "Budget", "Media budget", "Budget per Inhabitant", "Number visits", "Users", "Number of loans", "Usage of ebooks", "Visitors events", "Percent Active Users")
Gruppen <- c("alle", "internal", "external")
# run cor-function for all groups named in "Gruppen"
for (i in Gruppen) {
group_name <- get(i)[1]
var_names <- get(i)[-1]
fun_cor(group_name, var_names)
}
# Plot Distributions
for (i in Years) {
for (j in Names) {
temp <- Main_Data %>% select(State, (paste0(j, " ", i))) %>% melt(id.vars="State")
plot <- ggplot(temp, aes(x=State, y=value, group=1)) +
geom_point(colour="olivedrab", size=2) +
xlab("Kanton") +
ylab((paste0("Verteilung für: ", j, " ", i))) +
theme(panel.grid.major.y = element_line(color = "slategray3")) +
coord_flip()
jpeg(file=paste0("Plots/Distributions/distribution_", j, "_", i, ".jpg"), width=800, height = 600)
print(plot)
dev.off()
}
}
## Perform Analysis for Article
# Call Modul for re-reading of Main Data, in case it has not been done before
source("Scripts/Global_Libraries.R")
source("Scripts/Modul_CalculateData.R")
source("Scripts/Global_Variables.R")
# Call libraries used just for this analysis
library(corrplot)
## Get tables and plot for all correlations
# Loop gets data for internal / external variables (in "Names") and cor-Plots with all of them. Also produces tables for all data / years
# Funtion to get cor-plots
fun_cor <- function(group_name, variables){
for (i in Years){
temp <- Main_Data %>% select(`Library ID`)
for (j in variables) {
temp2 <- Main_Data %>% select((paste0(j, " ", i)))
temp <- cbind(temp, temp2)
}
temp <- temp[ , -1]
temp[is.na(temp)] <- 0
assign(paste0("analysis_data_", i), as.data.frame(temp))
temp <- cor(temp)
assign(paste0("analysis_cor", i), temp)
png(file=paste0("Plots/Correlations/", group_name, "__", "cor_numbers_", i, ".png"), width=1000, height = 1000)
corrplot(temp, method = "number", col=colorRampPalette(c("red3", "gold2", "olivedrab"))(600))
dev.off()
png(file=paste0("Plots/Correlations/", group_name, "__", "cor_rounds_", i, ".png"), width=700, height = 700)
# corrplot(temp, col=COL1("Oranges"))
corrplot(temp, col=colorRampPalette(c("red3", "gold2", "olivedrab"))(600))
dev.off()
png(file=paste0("Plots/Correlations/", group_name, "__", "cor_FPC_", i, ".png"), width=700, height = 700)
corrplot(temp, method = 'square', order = 'FPC', type = 'lower', diag = FALSE, col=colorRampPalette(c("red3", "gold2", "olivedrab"))(600))
dev.off()
}
}
# Names and data for the investigated variables: (a) frist position must be the name of the group, (b) positions after that names of variables, (c) the group must be named in the "Gruppen"-list
alle <- c("all", "Number visits", "Users", "Permanent staff", "Permanent staff percentages", "Volunteer staff", "Opening hours per week", "Budget", "Media budget", "Collection physical", "Collection digital", "Seats", "Number events", "Number of loans", "Usage of ebooks", "Visitors events", "Budget per Inhabitant", "Percent Active Users")
internal <- c("interne_variablen", "Permanent staff", "Permanent staff percentages", "Volunteer staff", "Opening hours per week", "Collection physical", "Collection digital", "Seats", "Number events", "Number visits", "Users", "Number of loans", "Usage of ebooks", "Visitors events", "Percent Active Users")
external <- c("externe_variablen", "Budget", "Media budget", "Budget per Inhabitant", "Number visits", "Users", "Number of loans", "Usage of ebooks", "Visitors events", "Percent Active Users")
Gruppen <- c("alle", "internal", "external")
# run cor-function for all groups named in "Gruppen"
for (i in Gruppen) {
group_name <- get(i)[1]
var_names <- get(i)[-1]
fun_cor(group_name, var_names)
}
# Plot Distributions
for (i in Years) {
for (j in Names) {
temp <- Main_Data %>% select(State, (paste0(j, " ", i))) %>% melt(id.vars="State")
plot <- ggplot(temp, aes(x=State, y=value, group=1)) +
geom_point(colour="olivedrab", size=2) +
xlab("Kanton") +
ylab((paste0("Verteilung für: ", j, " ", i))) +
theme(panel.grid.major.y = element_line(color = "slategray3")) +
coord_flip()
jpeg(file=paste0("Plots/Distributions/distribution_", j, "_", i, ".jpg"), width=800, height = 600)
print(plot)
dev.off()
}
}
# Distribution for Spacial formation - 3
for (i in Years) {
for (j in Names) {
# Get Data
temp <- Main_Data %>% select("State", "Spacial formation", (paste0(j, " ", i))) %>% melt(id.vars=c("State", "Spacial formation"))
# Filter Data not in the "Raumgliederungen"-file
temp <- temp %>% filter(`Spacial formation` != 0)
# Order Data for plot
temp <- temp %>% mutate(`Spacial formation` = factor(`Spacial formation`, levels=c("Ländlich", "Agglomeration", "Städtisch")))
plot <- ggplot(temp, aes(x=`Spacial formation`, y=value, group=1)) +
geom_point(colour="olivedrab", size=2) +
xlab("Räumliche Gliederung") +
ylab((paste0("Verteilung für: ", j, " ", i))) +
theme(panel.grid.major.y = element_line(color = "slategray3")) +
coord_flip()
plot
jpeg(file=paste0("Plots/Spacial3/distribution_", j, "_", i, ".jpg"), width=700, height = 500)
print(plot)
dev.off()
}
}
# Compare groups spacial
library(compareGroups)
for (i in Years) {
temp <- Main_Data %>% select(`Spacial formation`)
for (j in Names) {
temp_data <- Main_Data %>% select((paste0(j, " ", i)))
temp <- cbind(temp, temp_data)
}
temp <- temp %>% filter(`Spacial formation` != 0)
temp2 <- compareGroups(`Spacial formation` ~., temp, method = 2)
temp3 <- createTable(temp2, show.all = TRUE)
export2csv(temp3, paste0("Tables/CompareGroups/Spacial3/", i, ".csv"))
export2html(temp3, paste0("Tables/CompareGroups/Spacial3/", i, ".html"))
}
# Compare groups laws
library(compareGroups)
Data <- read_xlsx("Data/Liste Bibliotheksgesetze.xlsx")
Data <- Data %>% left_join(., Main_Data, by="State")
for (i in Years) {
temp <- Data %>% select(`Library law`)
for (j in Names) {
temp_data <- Data %>% select((paste0(j, " ", i)))
temp <- cbind(temp, temp_data)
}
# temp <- temp %>% filter(`Library law` != 0)
temp2 <- compareGroups(`Library law` ~., temp, method = 2)
temp3 <- createTable(temp2, show.all = TRUE)
export2csv(temp3, paste0("Tables/Library laws/", i, ".csv"))
export2html(temp3, paste0("Tables/Library laws/", i, ".html"))
}
