"inst/git@gitlab.iiasa.ac.at:mind-step/fadnutilspackage.git" did not exist on "fa4cf1b5049f0ee40d829ecc96dbe44e56955437"
Newer
Older
rm(list=ls())
library(fadnUtils)
requiredPackages = c('fadnUtils','data.table', 'devtools','jsonlite', 'ggplot2', 'tidyverse')
for(p in requiredPackages){
if(!require(p,character.only = TRUE)) install.packages(p)
library(p,character.only = TRUE)
}
CurrentProjectDirectory = "D:/data/fadn/lieferung_20210414/yang/fadn_work_space"
set.data.dir(CurrentProjectDirectory)
# load str data
str.dir <- "str_dir"
str_data <- readRDS(paste0(get.data.dir(),"/rds/",str.dir,"/fadn.str.all.rds"))
nuts.heatmap.ts <- function(group.by, fadn.data.info){
fadn.data.info = str_data$info
fadn.data.info = str_data$info
#todo: check folder
ifelse(!dir.exists(paste0(CurrentProjectDirectory,"/plot")),
dir.create(paste0(CurrentProjectDirectory,"/plot")), FALSE)
# dir.create(paste0(CurrentProjectDirectory,"/plot"), FALSE)
dir.create(paste0(CurrentProjectDirectory,"/plot/", "fadn_",deparse(substitute(group.by)),"_plots"),
showWarnings = FALSE)
countries <- unique(fadn.data.info$COUNTRY)
for (country in countries){
heatmap_data <- fadn.data.info %>%
filter(COUNTRY == country) %>%
count({{group.by}},YEAR) %>%
arrange(YEAR) %>%
# pivot_wider(names_from = YEAR,values_from=n) %>%
mutate(across(3:last_col(),function(x)ifelse(is.na(x),0,1)))
# pivot_longer(c(`2004`:`2018` ), names_to = "YEAR", values_to = "n")
heatmap_data <- data.frame(lapply(heatmap_data,as.character))
# if (NROW(heatmap_data$NUTS3 %>% unique()) >100 ) {
# text.size = 3
# } else{text.size = 11}
print(country)
text.size = 11
p <- heatmap_data %>% ggplot(aes(YEAR, {{group.by}}, fill= n)) +
geom_tile() +
# theme() +
ggtitle(country) + xlab("YEAR") + ylab("NUTS") +
theme(axis.text.y = element_text(size = text.size),legend.position="none")
#
# p_name <- country
#
# assign(p_name, heatmap_data %>% ggplot ( aes(YEAR,NUTS2, fill= n)) + geom_tile() +
# theme(legend.position="none") +
# ggtitle(country))
# print(p)
path_png <- paste0(CurrentProjectDirectory,"/plot/","fadn_",deparse(substitute(group.by)),"_plots/")
ggplot2::ggsave(plot = p,
filename = paste0(path_png,country,"ggplot2_",".png"),
width = 18, height = 8,
device = "png")
ggplot2::ggsave(plot = p,
filename = paste0(CurrentProjectDirectory,"/plot/","fadn_",deparse(substitute(group.by)),"_plots/","ts",".jpeg"),
device = "jpeg")
ggplot2::save_plot(plot = p,
filename = paste0(path_png,country,"_saveplot_",".png"),
width = 18, height = 8)
png(paste0(path_png,country,".png"))
print(p)
dev.off()
}
}
fadnUtils::nuts.heatmap.group(NUTS1,str_data$info)
fadnUtils::nuts.heatmap.group(NUTS2,str_data$info)
fadnUtils::nuts.heatmap.group(REGION,str_data$info)
nuts.heatmap.ts(NUTS1,"none")