0
votes

Is it possible to use R "likert" package to plot frequency data in multiple groups? I have following data:

       Years                job_sector gender  n  freq
1  2000-2004      Academic institution Female 46 0.336
2  2000-2004      Academic institution   Male 91 0.664
3  2000-2004        For-profit company Female 28 0.431
4  2000-2004        For-profit company   Male 37 0.569
5  2000-2004         Government agency Female 15 0.441
6  2000-2004         Government agency   Male 19 0.559
7  2000-2004 Independent/self-employed Female  1 0.500
8  2000-2004 Independent/self-employed   Male  1 0.500
9  2000-2004   Non-profit organization Female  6 0.500
10 2000-2004   Non-profit organization   Male  6 0.500
11 2000-2004      Unknown or Undecided Female 17 0.395
12 2000-2004      Unknown or Undecided   Male 26 0.605
13 2005-2009      Academic institution Female 68 0.447
14 2005-2009      Academic institution   Male 84 0.553
15 2005-2009        For-profit company Female 42 0.532
16 2005-2009        For-profit company   Male 37 0.468
17 2005-2009         Government agency Female 22 0.500
18 2005-2009         Government agency   Male 22 0.500
19 2005-2009 Independent/self-employed Female  1 1.000
20 2005-2009   Non-profit organization Female 11 0.688
21 2005-2009   Non-profit organization   Male  5 0.312
22 2005-2009      Unknown or Undecided Female  8 0.296
23 2005-2009      Unknown or Undecided   Male 19 0.704
24 2010-2014      Academic institution Female 63 0.485
25 2010-2014      Academic institution   Male 67 0.515
26 2010-2014        For-profit company Female 45 0.562
27 2010-2014        For-profit company   Male 35 0.438
28 2010-2014         Government agency Female 22 0.478
29 2010-2014         Government agency   Male 24 0.522
30 2010-2014 Independent/self-employed Female  1 1.000
31 2010-2014   Non-profit organization Female  4 0.500
32 2010-2014   Non-profit organization   Male  4 0.500
33 2010-2014      Unknown or Undecided Female  9 0.529
34 2010-2014      Unknown or Undecided   Male  8 0.471

I would like to display the "Male","Female" frequency of as Likert percent in each job_sector. And within each job_sector, there are 3 groups: "2000-2004","2005-2009" and "2010-2014".

EDITED (adding code):

I used following code to plot stacked bar chart. But I want to draw it as "likert" plot. But from "likert" example, it takes only raw counts not the summarized frequency data.

p <- ggplot(gendYrSect, aes(x=Years,y=freq,fill=gender)) + geom_bar(stat="identity") + facet_grid(job_sector ~ .)
p <- p + coord_flip()
p
1
Did you try anything first? Can you show code you've tried that didn't work?MrFlick

1 Answers

0
votes

I found the solution using the "likert" function from R package "HH". I reformat the data to

    > gendYrSect
Source: local data frame [18 x 4]
Groups: Years, job_sector [18]

       Years                job_sector Female  Male
      (fctr)                    (fctr)  (dbl) (dbl)
1  2000-2004      Academic institution     46    91
2  2000-2004        For-profit company     28    37
3  2000-2004         Government agency     15    19
4  2000-2004 Independent/self-employed      1     1
5  2000-2004   Non-profit organization      6     6
6  2000-2004      Unknown or Undecided     17    26
7  2005-2009      Academic institution     68    84
8  2005-2009        For-profit company     42    37
9  2005-2009         Government agency     22    22
10 2005-2009 Independent/self-employed      1     0
11 2005-2009   Non-profit organization     11     5
12 2005-2009      Unknown or Undecided      8    19
13 2010-2014      Academic institution     63    67
14 2010-2014        For-profit company     45    35
15 2010-2014         Government agency     22    24
16 2010-2014 Independent/self-employed      1     0
17 2010-2014   Non-profit organization      4     4
18 2010-2014      Unknown or Undecided      9     8

Then using the code below, I was able to get the plot I want.

library(HH)
likert(Years ~ . | job_sector, gendYrSect, as.percent=TRUE, main="Gender distribution in different job sectors")

likert plot with multiple groups