123 lines
3.7 KiB
R
Raw Normal View History

# Created By Miha 23.4.2021
#------------ DESC ------------#
# Podatki bodo pridobljeni v
# dveh stolpcih in brez
# naslovov. Gre za plain tekst
# oz labele in števila
# ki ji preberemo in prikažemo
# na radar grafu
# Prvi stolpec so labele in
# drugi stolpec vrednosti
#---------- //DESC// ----------#
#----------------- ENCODING 1KA STREŽNNIK ----------------#
# Nastavimo encoding za potrebe strežnika
# Pogosto se na 1KA strežniku pokvarijo šumniki
# zato šumniki (v PDF poročilu) lokalno delajo
# na strežniku pa ne
Sys.setlocale(category = "LC_ALL", locale = "slovenian")
#--------------- //ENCODING 1KA STREŽNNIK// --------------#
##############################
# RADAR CHART FOR NIJZ
##############################
#------------------ LIBRARIES -------------------#
# required libraries (radar chart)
library(fmsb)
# required libraries export image
library(Cairo)
#---------------- //LIBRARIES// -----------------#
# #-------------------- CUSTOM FUNCTIONS ------------------------#
# # In case of slovenian ČŽŠ we have problems when using PDF to
# # capture image and saving it on 1KA server, so we replace them
# replace.characters <- function(vector.to.tidy){
# vector.to.tidy <- gsub("-", "", vector.to.tidy)
# vector.to.tidy <- gsub(" ", "", vector.to.tidy)
# vector.to.tidy <- gsub("\\.", "", vector.to.tidy)
# vector.to.tidy <- gsub("\\&", "", vector.to.tidy)
# vector.to.tidy <- gsub("\u010C", "C", vector.to.tidy)
# vector.to.tidy <- gsub("\u0160", "S", vector.to.tidy)
# vector.to.tidy <- gsub("\u017D", "Z", vector.to.tidy)
# vector.to.tidy <- gsub("\u010D", "c", vector.to.tidy)
# vector.to.tidy <- gsub("\u0161", "s", vector.to.tidy)
# vector.to.tidy <- gsub("\u017E", "z", vector.to.tidy)
# vector.to.tidy <- gsub("\u017E", "z", vector.to.tidy)
# vector.to.tidy <- gsub("[(\\...\\,)]", "", vector.to.tidy)
# return(vector.to.tidy)
# }
# #------------------ //CUSTOM FUNCTIONS// ----------------------#
# Dobimo id respondenta, ker je ta stevilka v imenu csv datoteke in tudi v imenu grafa, ki se potem zgenerira
params <- commandArgs(trailingOnly=TRUE)
respondent_id <- params[1]
#------------------------------ READ DATA ----------------------------#
# Import data
data <- read.csv2(
2021-04-26 12:26:32 +02:00
paste0("../../admin/survey/modules/mod_NIJZ/temp/nijz_", respondent_id, ".csv"),
sep = ";",
header = FALSE,
stringsAsFactors = FALSE,
encoding = 'UTF-8'
)
# Remove missing values
data <-
subset(data,
!is.na(data$V2) | data$V2 < 0)
#--------------------------- // READ DATA // ------------------------#
#-------------------------- RADAR CHART -----------------------------#
2021-04-26 12:26:32 +02:00
CairoPNG(paste0('../../admin/survey/modules/mod_NIJZ/results/radar_', respondent_id, '.png'), width = 900, height = 700) # Export chart to png
# Create rang which will be labeld in grapf (10 likert scale)
myrange <- c(min(data$V2), max(data$V2))
# create a data frame with the max and min as the first two rows
mydf <-
as.data.frame(rbind(max = myrange[2], min = myrange[1], data$V2),
stringsAsFactors = FALSE)
# Add names which will be displayed as labels in
# chart and also their means in parentheses
labels <- gsub('(.{1,30})(\\s|$)', '\\1\n', data$V1)
colnames(mydf) <- labels
# Deljenje besed zaradi preglednosti
par(col="#004078", font = 2)
# Plot a radar chart
radarchart(
mydf,
pcol = "#D0D0D0",
pfcol = scales::alpha("#D0D0D0", 0.5),
# Customize the grid
cglcol = scales::alpha("grey", 0.6),
cglty = 1,
cglwd = 1,
# Customize the axis
axislabcol = "black",
na.itp = FALSE,
plwd = 3,
plty = 1,
seg = max(data$V2),
axistype = 1,
caxislabels = min(data$V2):max(data$V2),
centerzero = TRUE
)
#------------------------ //RADAR CHART//----------------------------#
dev.off()