R - Graphs with information from different columns

0

Hello,

I have the following problem: I need to create a table and a graph with information about level of education for different positions of the firm for different years and regions.

I have 4 levels of education (fundinc, medioinc, superiorinc and supdout) and 3 levels of positions (support, operational and strategic).

Each level of education and each position is a column (if fundinc == 1, the others are 0, if support == 1, operational and strategic are 0).

Example:

fundinc | medioinc | superiorinc | supdout | apoio | operacional | estrategico
1       | 0        | 0           | 0       | 1     | 0           | 0
0       | 1        | 0           | 0       | 0     | 1           | 0
0       | 0        | 1           | 0       | 0     | 0           | 1
0       | 0        | 1           | 0       | 0     | 0           | 1
0       | 1        | 0           | 0       | 1     | 0           | 0
1       | 0        | 0           | 0       | 1     | 0           | 0
.
. 
.

The databases are separated by year and region (date2010north-east, date2010north, ..., data2016south, date2016sul).

** Any suggestions on how to do this? I'm completely lost.

*** I want to see what level of education each post, for example, how many "fundinc", "medioinc", etc., are in the "support" position and others. I do not know which chart can present this better, maybe a common barplot.

I tried to create a function

pegaescolaridadeapoio = function (base) {

  #Fundamental incompleto

  a <- base[base$fundinc==1 & base$apoio==1, ]

  #Medio incompleto

  b <- base[base$medioinc==1 & base$apoio==1,]

  #Superior incompleto

  c <- base[base$superiorinc==1 & base$apoio==1,]

  #superior e outros

  d <- base[base$supdout==1 & base$apoio==1,]

  vetor <- c(nrow(a),nrow(b),nrow(c),nrow(d))

  return (vetor)
}

After that, I tried to create vectors and put them in tables, but without success.

Thank you in advance.

    
asked by anonymous 10.04.2018 / 15:34

1 answer

1

For first you will need to rearrange your dataset, so that you have only 2 columns:

base2 <- read.csv2("base2.csv") # Base de dados do seu exemplo
nova.base <- data.frame(Escolaridade = names(base2[1:4])[max.col(base2[1:4])],
                        Cargo = names(base2[5:7])[max.col(base2[5:7])])

Simple table:

with(nova.base, table(Escolaridade, Cargo))
             Cargo
Escolaridade  apoio estrategico operacional
  fundinc         2           0           0
  medioinc        1           0           1
  superiorinc     0           2           0

Simple chart:

library(ggplot2)
ggplot(nova.base, aes(x = Escolaridade, fill = Cargo)) +
  geom_bar()

    
25.10.2018 / 19:32