1

I am currently trying to plot the evolution of the distribution of jobs between long term jobs, short term jobs, apprenticeships etc, in a dataset representing the data surrounding the wages of a firm's employees. I thus would like to plot a pie chart per year, yet when I run this code, it doesn't work :

library(ggplot2)
tab <- table(liste_complete$code_contrat) 
prop.table(tab)
pie(tab) + facet_wrap(~annee)

I would also welcome any advice on a better plot to represent the evolution of the repartition of type of contract ("code_contrat") across years, hierarchical level (variable "niveau"), type of jobs ("code_statut"),..

Here is the structure of my dataset :

structure(list(numero = c("133", "62", "75", "76", "86", "281"
), tranche_age = c("20-30", "20-30", "20-30", "20-30", "20-30", 
"20-30"), tranche_anciennete = c("5 ans et moins", "5 à 10 ans", 
"5 ans et moins", "5 ans et moins", "5 à 10 ans", "5 à 10 ans"
), code_statut = c("C", "E", "E", "E", "E", "E"), code_contrat = c("A", 
"A", "A", "A", "A", "A"), taux_demploi_mois = c(100, 100, 100, 
100, 100, 100), echelon = c("E1  ", "    ", "    ", "    ", "    ", 
"    "), niveau = c("N7  ", "    ", "    ", "    ", "    ", "    "
), brut_mensuel = c(NA, 786.13, 1156.95, 1156.95, 904.79, 904.79
), estimation_annuelle = c(NA, 10219.69, 15040.35, 15040.35, 
11762.27, 11762.27), annee = c(2017, 2017, 2017, 2017, 2017, 
2017), primes_en_montant = c(NA_real_, NA_real_, NA_real_, NA_real_, 
NA_real_, NA_real_), primes_en_pourcentage = c(NA_real_, NA_real_, 
NA_real_, NA_real_, NA_real_, NA_real_)), row.names = c("6", 
"7", "8", "9", "10", "11"), class = "data.frame")
  • 1
    a few notes on your code! you execute ```prop.table(tab)``` but don't use it in the next line of code.```pie()``` is not a function from the ```ggplot2``` package. ```facet wrap``` is used to put graphs neatly next to each other but you are only making one graph. Try searching the web for piecharts with ```ggplot2``` you will find links telling you to use ```geom_bar``` or ```geom_col```. – Omniswitcher Aug 08 '22 at 13:36
  • 1
    annee column has only 1 distinct data point in your data which is 2017 so faceting wouldnt work. Nonethless i would advise you to use line chart where x is time, y is proportion and line color is job type (long,short). – Ege Can Aug 08 '22 at 13:40
  • 1
    You're trying to combine the `pie` from base with ggplot's `facet_wrap` and that won't work. Check this [faceted piechart with ggplot](https://stackoverflow.com/questions/22592789/faceted-piechart-with-ggplot) or https://stackoverflow.com/questions/65701081/r-pie-chart-in-facet – harre Aug 08 '22 at 13:44

0 Answers0