我正在处理一个需要按频率排序的图。我已经弄清楚了如何将y轴上的变量移动到降序,但是它是按x变量值而不是x变量出现的次数排序的。
我尝试使用这段代码
p<- ggplot(a, aes(x=reorder(Analyte,a$Concentration),y=a$Concentration), na.rm=TRUE)
,但不是按照我想要的方式排序。
a<-Analyte_Concentrations
p<- ggplot(a, aes(x=reorder(Analyte,a$Concentration),y=a$Concentration), na.rm=TRUE)
p + geom_boxplot(fill= "white", na.rm=TRUE) + coord_flip() +
geom_point(aes(color = Analyte)) + ggtitle(" Analyte Detection Concentrations ") +
xlab("Analytes (decreasing concentration)") + ylab("Concentration")
数据示例:
52 Nicotine -2.3010300
53 Nicotine -2.1549020
54 Nicotine -2.2218487
55 Nicotine -2.3010300
56 Nicotine -2.0000000
57 Nicotine -2.2218487
58 Nicotine -2.0457575
59 Nicotine -2.0969100
60 Nicotine -2.1549020
61 Tris(chloropropyl) phosphate -1.6989700
62 Tris(chloropropyl) phosphate -2.0000000
63 Tris(chloropropyl) phosphate -2.0000000
64 Tris(chloropropyl) phosphate -2.0000000
65 Tris(chloropropyl) phosphate -1.6989700
66 Tris(chloropropyl) phosphate -1.6989700
67 Tris(chloropropyl) phosphate -1.6989700
68 Tris(chloropropyl) phosphate -1.6989700
69 Tris(chloropropyl) phosphate -2.0000000
70 Tris(chloropropyl) phosphate -1.1549020
71 cis-Testosterone -2.1249387
72 cis-Testosterone -2.2596373
73 Acesulfame-K -0.9208188
74 Acesulfame-K -1.0969100
75 Acesulfame-K -1.1549020
76 Acesulfame-K -0.9208188
77 Acesulfame-K -0.9208188
78 Acesulfame-K -1.2218487
79 Acesulfame-K -1.2218487
80 Acesulfame-K -1.2218487
81 Acesulfame-K -0.7958800
82 Acesulfame-K -1.2218487
83 Acesulfame-K -1.2218487
84 Acesulfame-K -1.6989700
85 Acesulfame-K -0.9208188
86 Acesulfame-K -0.9586073
87 Acesulfame-K -0.8239087
88 Acesulfame-K -0.7695511
89 Acesulfame-K -0.1611509
90 Acesulfame-K -0.9586073
91 Acesulfame-K -0.9586073
92 Acesulfame-K -1.3979400
93 Acesulfame-K -0.9208188
94 Acesulfame-K -1.0000000
95 Acesulfame-K -1.6989700
96 Acesulfame-K -0.8860566
97 Acesulfame-K -1.0457575
98 Acesulfame-K -0.8860566
99 Acesulfame-K -1.0000000
100 Acesulfame-K -0.3872161
101 Cotinine -3.0000000
102 Cotinine -3.0000000
103 Cotinine -3.0000000
104 Cotinine -3.0000000
105 Cotinine -3.0000000
106 Cotinine -3.0000000
107 Cotinine -3.0000000
108 Cotinine -3.0000000
109 Cotinine -2.6989700
110 Cotinine -3.0000000
111 Cotinine -3.0000000
112 Cotinine -3.0000000
113 Cotinine -3.0000000
114 Cotinine -2.6989700
115 Cotinine -3.0000000
116 Cotinine -3.0000000
117 Cotinine -2.6989700
118 Cotinine -3.0000000
119 Cotinine -3.0000000
120 Cotinine -2.6989700
121 Cotinine -2.6989700
122 Cotinine -2.5228787
123 Cotinine -3.0000000
124 Cotinine -3.0000000
125 Cotinine -3.0000000
126 Cotinine -3.0000000
127 Cotinine -3.0000000
128 Sulfamethoxazole -3.0000000
129 Sulfamethoxazole -3.0000000
130 Sulfamethoxazole -3.0000000
131 Sulfamethoxazole -3.0000000
132 Sulfamethoxazole -3.0000000
133 Sulfamethoxazole -2.6989700
134 Sulfamethoxazole -2.6989700
135 Sulfamethoxazole -3.0000000
136 Sulfamethoxazole -2.6989700
137 Sulfamethoxazole -2.6989700
138 Sulfamethoxazole -2.6989700
139 Sulfamethoxazole -2.6989700
140 Sulfamethoxazole -2.6989700
141 Sulfamethoxazole -2.6989700
142 Sulfamethoxazole -2.6989700
143 Sulfamethoxazole -2.5228787
144 Sulfamethoxazole -2.6989700
145 Sulfamethoxazole -2.6989700
146 Sulfamethoxazole -2.6989700
147 Sulfamethoxazole -2.6989700
148 Sulfamethoxazole -2.6989700
149 Sulfamethoxazole -2.6989700
150 Sulfamethoxazole -2.6989700
151 Sulfamethoxazole -3.0000000
152 Sulfamethoxazole -2.6989700
153 Sulfamethoxazole -2.6989700
154 Sulfamethoxazole -2.6989700
155 Sulfamethoxazole -2.6989700
156 Sulfamethoxazole -3.0000000
157 Sulfamethoxazole -3.0000000
158 Sulfamethoxazole -3.0000000
159 Sulfamethoxazole -2.6989700
160 Sulfamethoxazole -2.6989700
161 Sulfamethoxazole -2.6989700
162 Sulfamethoxazole -3.0000000
163 DEET -2.0969100
164 DEET -2.1549020
165 DEET -1.9208188
166 DEET -2.3010300
167 DEET -2.0969100
168 DEET -2.2218487
169 DEET -1.8239087
170 DEET -2.2218487
171 DEET -2.1549020
172 DEET -2.0969100
173 DEET -2.1549020
174 DEET -2.2218487
175 DEET -2.3010300
176 DEET -2.1549020
177 DEET -2.0969100
178 DEET -2.0969100
179 DEET -2.2218487
180 DEET -2.1549020
181 DEET -2.2218487
182 DEET -2.2218487
183 DEET -2.2218487
184 DEET -2.1549020
185 DEET -1.9586073
186 DEET -2.0000000
187 DEET -2.0969100
188 DEET -2.0969100
189 DEET -2.0969100
190 DEET -2.2218487
191 DEET -2.3010300
192 DEET -2.1549020
193 DEET -2.1549020
194 DEET -2.2218487
195 DEET -2.2218487
196 DEET -2.0969100
197 DEET -2.2218487
198 DEET -1.8239087
199 DEET -1.6382722
200 DEET -1.8860566
201 DEET -2.2218487
202 DEET -1.8538720
203 DEET -1.9208188
204 DEET -1.8538720
205 DEET -2.0457575
206 DEET -2.1549020
207 DEET -2.0000000
208 DEET -2.1549020
209 DEET -2.3010300
210 DEET -2.2218487
211 DEET -2.2218487
212 DEET -2.2218487
213 DEET -1.8239087
214 DEET -2.2218487
215 DEET -2.0457575
216 DEET -2.0969100
217 DEET -2.0000000
218 DEET -2.1549020
219 DEET -2.2218487
220 DEET -2.2218487
221 DEET -2.2218487
222 DEET -1.8239087
223 DEET -2.2218487
224 DEET -2.0969100
225 DEET -2.3010300
226 DEET -2.1549020
227 DEET -1.8538720
228 DEET -1.8538720
229 DEET -2.2218487
230 DEET -2.0457575
231 DEET -2.3010300
我希望该图表以减少的出现水平排序。因此,在上面的数据摘录中,Det位于顶部,尼古丁位于底部。