Setup

knitr::opts_chunk$set(dev = "svglite",
                      fig.path = "../images/",
                      dpi = 300)

Loading the neccesary libraries

library(readr)        # load csv
library(HH)           # likert plotting

We load the tables.

science <- read_csv("../data/cleaned/science.csv")
experience <- read_csv("../data/cleaned/experience.csv")
efficiency <- read_csv("../data/cleaned/efficiency.csv")


confidence <- read_csv("../data/cleaned/confidence.csv")
fallacies <- read_csv("../data/cleaned/fallacies.csv")
novelty <- read_csv("../data/cleaned/novelty.csv")
replication <- read_csv("../data/cleaned/replication.csv")
statistics <- read_csv("../data/cleaned/statistics.csv")

We add a function to set percentages in plots.

origNames = colnames(data)
panel <- function(...){
  panel.likert(...)
  vals <- list(...)
  DF <- data.frame(x=vals$x, y=vals$y, groups=vals$groups)
  grps <- as.character(DF$groups)
  for(i in 1:length(origNames)){
    grps <- sub(paste0('^',origNames[i]),i,grps)
  }
  DF <- DF[order(DF$y,grps),]
  DF$correctX <- ave(DF$x,DF$y,FUN=function(x){
    x[x < 0] <- rev(cumsum(rev(x[x < 0]))) - x[x < 0]/2
    x[x > 0] <- cumsum(x[x > 0]) - x[x > 0]/2
    return(x)
  })
  subs <- sub(' Positive$','',DF$groups)
  collapse <- subs[-1] == subs[-length(subs)] & DF$y[-1] == DF$y[-length(DF$y)]
  DF$abs <- abs(DF$x)
  DF$abs[c(collapse,FALSE)] <- DF$abs[c(collapse,FALSE)] + DF$abs[c(FALSE,collapse)]
  DF$correctX[c(collapse,FALSE)] <- 0
  DF <- DF[c(TRUE,!collapse),]
  DF$perc <- round(ave(DF$abs,DF$y,FUN=function(x){x/sum(x) * 100}), 0)
  DF$perc <- paste0(DF$perc,'%')
  DF$perc[DF$perc == "0%"] <- ""
  panel.text(x=DF$correctX, y=DF$y, label=DF$perc, cex=1)
}

We start by plotting the science table.

likert(Measures ~ .,
       data=science,
       as.percent=TRUE,
       positive.order=TRUE,
       main=list("Valore cada una de las siguientes cuestiones relacionadas con su opinión sobre la ciencia", cex=3),
       rightAxis=F,
       #col=c("#CA0020", "#F4A582", "#F7F7F7", "#92C5DE", "#0571B0"),
       #panel=panel,
       ylab=NULL,
       xlab=list("Percent", cex=3),
       #auto.key=list(cex=3, columns=1, rect=list(col=c("#CA0020", "#F4A582", "#F7F7F7", "#92C5DE", "#0571B0"), border = "black")),
       auto.key=list(cex=3, columns=1),
       #borders = list(),
       scales=list(y=list(cex=3),
                            xlab=list(cex=3)
                   )
       )

Now the experience table.

likert(Measures ~ .,
       data=experience,
       as.percent=TRUE,
       positive.order=TRUE,
       main=list("Marque la opción que mejor represente su conocimiento y experiencia con cada práctica en los últimos 5 (cinco) años", cex=3),
       rightAxis=F,
       #panel=panel,
       ylab=NULL,
       xlab=list("Percent", cex=3),
       auto.key=list(cex=3, columns=1),
       scales=list(y=list(cex=3),
                            xlab=list(cex=3)
                   )
       )

Finally, the efficiency table.

likert(Measures ~ .,
       data=efficiency,
       as.percent=TRUE,
       positive.order=TRUE,
       main=list("Elija la opción que mejor represente cuán importante considera que es cada una de las siguientes prácticas para mejorar la calidad y eficiencia de las investigaciones en su campo", cex=3),
       rightAxis=F,
       #panel=panel,
       ylab=NULL,
       xlab=list("Percent", cex=3),
       auto.key=list(cex=3),
       scales=list(y=list(cex=3),
                            xlab=list(cex=3)
                   )
       )

likert(Measures ~ .,
       data=confidence,
       as.percent=TRUE,
       positive.order=TRUE,
       main=list("Confidence", cex=3),
       rightAxis=F,
       #panel=panel,
       ylab=NULL,
       xlab=list("Percent", cex=3),
       auto.key=list(cex=3, columns=1),
       scales=list(y=list(cex=3),
                            xlab=list(cex=3)
                   )
       )

likert(Measures ~ .,
       data=fallacies,
       as.percent=TRUE,
       positive.order=TRUE,
       main=list("Fallacies", cex=3),
       rightAxis=F,
       #panel=panel,
       ylab=NULL,
       xlab=list("Percent", cex=3),
       auto.key=list(cex=3),
       scales=list(y=list(cex=3),
                            xlab=list(cex=3)
                   )
       )

likert(Measures ~ .,
       data=novelty,
       as.percent=TRUE,
       positive.order=TRUE,
       main=list("Novelty", cex=3),
       rightAxis=F,
       #panel=panel,
       ylab=NULL,
       xlab=list("Percent", cex=3),
       auto.key=list(cex=3),
       scales=list(y=list(cex=3),
                            xlab=list(cex=3)
                   )
       )

likert(Measures ~ .,
       data=replication,
       as.percent=TRUE,
       positive.order=TRUE,
       main=list("Replication", cex=3),
       rightAxis=F,
       #panel=panel,
       ylab=NULL,
       xlab=list("Percent", cex=3),
       auto.key=list(cex=3, columns=1),
       scales=list(y=list(cex=3),
                            xlab=list(cex=3)
                   )
       )

likert(Measures ~ .,
       data=statistics,
       as.percent=TRUE,
       positive.order=TRUE,
       main=list("Statistics", cex=3),
       rightAxis=F,
       #panel=panel,
       ylab=NULL,
       xlab=list("Percent", cex=3),
       auto.key=list(cex=3, columns=1),
       scales=list(y=list(cex=3),
                            xlab=list(cex=3)
                   )
       )