我正在尝试创建一个条形图,显示使用五分位数从表中分组的一些变量的计数。我希望此图表按性别细分(在数据中)。
因此,它应该向我显示偏见剪切以及在按性别划分的数据中显示偏见的频率。
prejiducequint = quantile(dta.sub2$WHPREJUDICE6R,seq(0,1, length = 5))
prejiducecut = cut(dta.sub2$WHPREJUDICE6R, breaks = incomequint)
p = ggplot(dta.sub2, aes(prejiducecut, fill = FEMALE6)) +
geom_bar(position = "dodge")
p
这是数据
WHPREJUDICE6R prejiducecut FEMALE6
1 -0.005 (-0.0125,0] 0
2 0.075 (0.0275,1] 0
3 0.000 (-0.0125,0] 0
4 0.000 (-0.0125,0] 1
5 -0.020 (-0.44,-0.0125] 1
6 0.130 (0.0275,1] 1
7 0.090 (0.0275,1] 0
8 0.230 (0.0275,1] 0
9 0.100 (0.0275,1] 1
10 0.870 (0.0275,1] 1
11 -0.130 (-0.44,-0.0125] 1
12 -0.010 (-0.0125,0] 1
13 0.005 (0,0.0275] 0
14 -0.010 (-0.0125,0] 1
15 -0.060 (-0.44,-0.0125] 1
16 0.000 (-0.0125,0] 1
17 -0.010 (-0.0125,0] 1
18 0.000 (-0.0125,0] 1
19 -0.075 (-0.44,-0.0125] 1
20 0.005 (0,0.0275] 1
21 -0.010 (-0.0125,0] 0
22 -0.060 (-0.44,-0.0125] 1
23 0.500 (0.0275,1] 0
24 0.020 (0,0.0275] 0
25 0.135 (0.0275,1] 0
26 -0.055 (-0.44,-0.0125] 1
27 -0.440 <NA> 0
28 0.000 (-0.0125,0] 0
29 -0.065 (-0.44,-0.0125] 0
30 0.000 (-0.0125,0] 1
31 0.035 (0.0275,1] 1
32 -0.005 (-0.0125,0] 0
33 0.000 (-0.0125,0] 1
34 -0.290 (-0.44,-0.0125] 1
35 0.005 (0,0.0275] 1
36 0.300 (0.0275,1] 0
37 0.005 (0,0.0275] 1
38 0.070 (0.0275,1] 1
39 -0.195 (-0.44,-0.0125] 1
40 -0.260 (-0.44,-0.0125] 0
41 -0.040 (-0.44,-0.0125] 1
42 0.720 (0.0275,1] 0
43 0.045 (0.0275,1] 1
44 0.125 (0.0275,1] 1
45 0.035 (0.0275,1] 0
46 0.005 (0,0.0275] 1
47 0.000 (-0.0125,0] 0
48 0.000 (-0.0125,0] 0
49 0.000 (-0.0125,0] 1
50 0.010 (0,0.0275] 1
51 0.495 (0.0275,1] 1
52 0.000 (-0.0125,0] 1
53 0.000 (-0.0125,0] 1
54 0.010 (0,0.0275] 0
55 -0.015 (-0.44,-0.0125] 1
56 -0.110 (-0.44,-0.0125] 0
57 0.000 (-0.0125,0] 0
58 0.065 (0.0275,1] 1
59 0.255 (0.0275,1] 1
60 -0.020 (-0.44,-0.0125] 1
61 0.070 (0.0275,1] 1
62 0.000 (-0.0125,0] 0
63 1.000 (0.0275,1] 0
64 0.000 (-0.0125,0] 1
65 0.490 (0.0275,1] 0
66 -0.005 (-0.0125,0] 1
67 0.000 (-0.0125,0] 0
68 0.010 (0,0.0275] 1
69 0.000 (-0.0125,0] 1
70 -0.065 (-0.44,-0.0125] 1
71 0.005 (0,0.0275] 0
72 -0.065 (-0.44,-0.0125] 0
73 0.060 (0.0275,1] 0
74 0.000 (-0.0125,0] 0
75 0.000 (-0.0125,0] 1
76 0.155 (0.0275,1] 0
77 -0.190 (-0.44,-0.0125] 0
78 0.000 (-0.0125,0] 0
79 -0.065 (-0.44,-0.0125] 0
80 0.005 (0,0.0275] 1
81 0.060 (0.0275,1] 0
82 -0.100 (-0.44,-0.0125] 1
83 0.000 (-0.0125,0] 1
84 0.005 (0,0.0275] 0
85 0.000 (-0.0125,0] 1
86 0.300 (0.0275,1] 1
87 -0.070 (-0.44,-0.0125] 1
88 0.430 (0.0275,1] 0
89 -0.060 (-0.44,-0.0125] 1
90 -0.005 (-0.0125,0] 1
91 0.000 (-0.0125,0] 1
92 -0.005 (-0.0125,0] 1
93 0.015 (0,0.0275] 0
94 -0.205 (-0.44,-0.0125] 0
95 0.000 (-0.0125,0] 1
96 0.045 (0.0275,1] 0
97 -0.075 (-0.44,-0.0125] 0
98 0.000 (-0.0125,0] 0
99 0.000 (-0.0125,0] 1
100 0.000 (-0.0125,0] 1
101 0.235 (0.0275,1] 0
102 -0.060 (-0.44,-0.0125] 1
103 0.505 (0.0275,1] 0
104 -0.185 (-0.44,-0.0125] 1
105 0.185 (0.0275,1] 0
106 -0.115 (-0.44,-0.0125] 0
107 0.005 (0,0.0275] 0
108 -0.440 <NA> 1
109 -0.100 (-0.44,-0.0125] 1
110 0.430 (0.0275,1] 1
111 -0.005 (-0.0125,0] 0
112 0.000 (-0.0125,0] 1
113 0.000 (-0.0125,0] 0
114 -0.120 (-0.44,-0.0125] 1
115 0.005 (0,0.0275] 0
116 0.145 (0.0275,1] 0
117 0.110 (0.0275,1] 0
118 -0.010 (-0.0125,0] 0
119 0.000 (-0.0125,0] 1
120 -0.005 (-0.0125,0] 0
121 -0.060 (-0.44,-0.0125] 0
122 0.120 (0.0275,1] 1
123 -0.240 (-0.44,-0.0125] 0
124 -0.005 (-0.0125,0] 0
125 0.000 (-0.0125,0] 1
126 -0.060 (-0.44,-0.0125] 0
127 -0.305 (-0.44,-0.0125] 1
128 0.050 (0.0275,1] 0
129 0.000 (-0.0125,0] 0
130 -0.005 (-0.0125,0] 0
131 -0.005 (-0.0125,0] 0
132 0.000 (-0.0125,0] 1
133 -0.045 (-0.44,-0.0125] 1
134 -0.005 (-0.0125,0] 0
135 0.000 (-0.0125,0] 1
136 -0.065 (-0.44,-0.0125] 1
137 0.000 (-0.0125,0] 1
138 0.055 (0.0275,1] 0
139 0.020 (0,0.0275] 1
140 0.000 (-0.0125,0] 0
141 0.000 (-0.0125,0] 0
142 -0.005 (-0.0125,0] 1
143 0.005 (0,0.0275] 1
该图制作完成,但是存在带性别的细分(FEMALE6)。女性6是基于性别的变量,值为0或1。