是否可以使用R“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中显示Likert百分比的“男性”,“女性”频率。在每个job_sector中,共有3组:“2000-2004”,“2005-2009”和“2010-2014”。
已编辑(添加代码):
我使用以下代码绘制堆积条形图。但我想把它描绘成“喜欢”的情节。但是从“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 :(得分:0)
我找到了使用&#34; likert&#34;来自R包的功能&#34; HH&#34;。我将数据重新格式化为
> 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")