我的数据看起来像这样:
df1 <- structure(list(truth = structure(c(1L, 60L, 60L, 1L, 60L, 1L,
51L, 60L, 1L, 51L, 51L, 51L, 1L, 60L, 1L, 1L, 1L, 1L, 51L, 51L,
60L, 1L, 51L, 60L, 60L, 51L, 1L, 51L, 51L, 60L, 1L, 51L, 60L,
60L, 60L, 60L, 51L, 51L, 1L, 51L, 60L, 60L, 51L, 60L, 51L, 1L,
60L, 60L, 1L, 51L), .Label = c("1", "2", "3", "4", "5", "6",
"7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17",
"18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28",
"29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
"40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50",
"51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61",
"62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72",
"73", "74", "75", "76", "77", "78", "79", "80", "81"), class = "factor"),
Value = c(-30.0770205345024, 11.7433058396476, 7.36998070970907,
-40.9432745219622, 11.2711232296384, 37.654418952948, 52.0790876912742,
9.24338996112739, 29.0493670430368, 49.1051619881392, 44.2985212410612,
43.6318989421322, 65.4604885768842, 8.53340577821466, 28.0911627592635,
-10.9056308891468, -30.7565582432717, -10.6123772579921,
72.062213840367, 48.7134304917154, 5.27055421605771, 84.0339742464238,
44.9513792584612, 8.69314684177602, 4.46763929211751, 67.201960023123,
18.8362161729668, 55.8315346585296, 42.795252431141, 10.6963690858218,
20.4073049396301, 72.4095655954934, 6.57602161344761, 11.3705463495041,
5.75891202331646, 4.4898446961011, 61.9778344010139, 45.713765588086,
-50.570124971873, 65.3016561445738, 13.413626538152, 5.37048273610232,
59.9860827960121, 12.1028140616031, 56.3708005716536, -29.5009161157071,
7.22681794770881, 4.27798086289943, -20.8395270111429, 57.8745694222055
)), .Names = c("truth", "Value"), row.names = c(88L, 126L,
288L, 232L, 78L, 76L, 83L, 237L, 52L, 62L, 275L, 194L, 103L,
117L, 262L, 184L, 25L, 205L, 119L, 203L, 15L, 64L, 74L, 225L,
297L, 176L, 277L, 197L, 5L, 105L, 7L, 38L, 12L, 285L, 63L, 201L,
56L, 155L, 247L, 128L, 240L, 72L, 44L, 51L, 29L, 82L, 249L, 57L,
112L, 8L), class = "data.frame")
我想生成这样的情节
df1 %>% ggplot(aes(x=truth, y=Value)) +
stat_summary(fun.data=mean_cl_boot, mult=1,
geom="pointrange", conf.int=0.95) +
theme_bw()
但我想根据每个人的平均值重新排序“真相”。在这个例子1,60,51。
我该怎么做?
谢谢!
答案 0 :(得分:3)
你可以像这样重新排序
ggplot(data = df1, aes(reorder(truth, truth),Value)) +
stat_summary(fun.data=mean_cl_boot, mult=1,
geom="pointrange", conf.int=0.95) +
theme_bw()
已编辑
如果您想根据“值”列重新排序,请执行此操作
ggplot(data = df1, aes(reorder(truth, Value),Value)) +
stat_summary(fun.data=mean_cl_boot, mult=1,
geom="pointrange", conf.int=0.95) +
theme_bw()
在任何情况下,如果您想根据Value列的降序值重新排序,您可以这样做:)
ggplot(data = df1, aes(reorder(truth, -Value),Value))