This and example, dataframe's variables and values are labeled, then We use the sjPlot package to build a beatiful output. First a dataframe is created:
require(randomNames)
## Loading required package: randomNames
require(sjPlot)
## Loading required package: sjPlot
# Reetiquetar variables
set.seed(12345)
id = 1:30
set.seed(12345)
ing = rnorm(30, mean = 162, sd = 6)
set.seed(12345)
x = ceiling(runif(30, 0, 5))
set.seed(12345)
y = ceiling(runif(30, 0, 3))
set.seed(12345)
z = randomNames(30)
datos = data.frame(id, ing, x, y, z)
Variables are labeled:
var_labels = c("Identificador variables", "Ingreso", "Candidato", "Región Colombia",
"Votante")
names(var_labels) = colnames(datos)
attributes(datos)$variable.labels = var_labels
Values are labeled:
x_label <- c(1, 2, 3, 4, 5)
names(x_label) <- c("Zuluaga", "Santos", "Ramírez", "López", "Peñalosa")
y_label <- c(1, 2, 3)
names(y_label) <- c("Región Central", "Región Pacífico", "Región Otros")
attributes(datos$x)$value.labels = x_label
attributes(datos$y)$value.labels = y_label
Variable and value labels are prepared for sjPlot
variables <- sji.getVariableLabels(datos)
values <- sji.getValueLabels(datos)
Analysis of x variable:
sjt.frq(datos$x, variableLabels = variables["x"], valueLabels = values[["x"]],
stringValue = "Valor", stringPerc = "Porcentaje", stringValidPerc = "Porcentaje valido",
stringMissingValue = "Perdidos", stringCumPerc = "Porcentaje acumulado",
alternateRowColors = T, showSummary = F)
## Warning: NAs introduced by coercion
Analysis of y variable:
sjt.frq(datos$y, variableLabels = variables["y"], valueLabels = values[["y"]],
stringValue = "Valor", stringPerc = "Porcentaje", stringValidPerc = "Porcentaje valido",
stringMissingValue = "Perdidos", stringCumPerc = "Porcentaje acumulado",
alternateRowColors = F, showSummary = F)
## Warning: NAs introduced by coercion