2016-02-25 26 views
0

是否可以使用R「likert」包來繪製多個組的頻率數據?我有如下的數據:是否可以使用「likert」包來繪製多個組的頻率數據?

 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 

我想顯示在每個job_sector「男性」,「女性」的作爲李克特%的頻率。在每個工作崗位內,有3個組:「2000-2004」,「2005-2009」和「2010-2014」。

編輯(添加代碼):

我用下面的代碼來繪製堆積條形圖。但我想把它畫成「likert」的情節。但是從「likert」的例子來看,它只採用原始計數而不是彙總的頻率數據。

p <- ggplot(gendYrSect, aes(x=Years,y=freq,fill=gender)) + geom_bar(stat="identity") + facet_grid(job_sector ~ .) 
p <- p + coord_flip() 
p 
+0

你第一次嘗試什麼嗎?你能顯示你嘗試過的代碼嗎? – MrFlick

回答

0

我發現該解決方案使用R包「HH」中的「likert」函數。我重新格式化數據到

> 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 

然後使用下面的代碼,我能夠得到我想要的陰謀。

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

likert plot with multiple groups

相關問題