按特定方面对geom_point进行排序

时间:2018-06-30 13:14:44

标签: r ggplot2 facet-grid

我有一个与ggplot相关的问题,应该很容易,但是我还没有找到答案。我正在尝试使用下面的代码和this dataset(11 kB)绘制多面图。

ggplot(plot.dat, aes(x = estimate, y = reorder(countryyear, estimate))) +
  geom_point() +
  geom_segment(aes(x=conf.low, xend=conf.high, yend=countryyear)) +
  facet_grid(. ~ facet) + 
  xlab("Random Effect Estimate") +
  ylab("") + scale_x_continuous(breaks=c(seq(0, 5, 1)), limits=c(0, 5)) +
  ggtitle("Random Slopes in Country*Year Groups from Northwestern Europe") +
  theme_minimal() + theme(plot.title = element_text(hjust = 0.5))

我希望countryyearestimate方面中Extreme Right的值来组织。不太确定如何按特定构面的值进行排序。任何想法都欢迎!谢谢。

更新:这是数据集随机子集的dput结构。它具有一些缺失的值,但是出于示例的目的它应该可以工作。我还更新了上面的完整版本的下载链接。

structure(list(estimate = c(1.41056902925372, 0.854859208455895, 
1.16012834593894, 0.871339033194504, 0.803272289946221, 1.17540386134493, 
0.996313357490551, 1.49940694539732, 1.33773365908762, 2.7318703090905, 
1.19131935418045, 1.12765907711738, 0.746741192261761, 0.985847015192172, 
0.912357310925342, 1.11582763712164, 1.21854572824977, 0.675712547978394, 
0.566955524699616, 1.32611743759365, 0.519648352294682, 0.591013596394243, 
1.30944973684044, 0.613722269599125, 1.13293279727271, 0.950788678552604, 
1.1599446923567, 1.11493952112913, 0.95336321045095, 1.39002327097034, 
0.794207546872633, 0.788545101449259, 1.01096883872495, 0.897407203907834, 
1.38391605229103, 1.35754760293107, 1.0718508539761, 0.542191158958878, 
0.757132752456427, 1.44172863221312, 1.04842251986171, 0.77260404885379, 
0.879288027642055, 1.09372353598088, 0.745484830381145, 1.21211217249353, 
0.628009608902132, 1.34864488674734), countryyear = structure(c(1L, 
2L, 4L, 5L, 7L, 9L, 10L, 12L, 13L, 26L, 28L, 29L, 31L, 32L, 34L, 
36L, 37L, 39L, 40L, 57L, 59L, 60L, 62L, 63L, 65L, 67L, 68L, 70L, 
71L, 73L, 75L, 76L, 89L, 90L, 92L, 94L, 95L, 103L, 104L, 106L, 
108L, 109L, 111L, 128L, 130L, 132L, 133L, 135L), .Label = c("AT02", 
"AT04", "AT06", "AT14", "AT16", "BE02", "BE04", "BE06", "BE08", 
"BE10", "BE12", "BE14", "BE16", "BG06", "BG08", "BG10", "BG12", 
"CH14", "CZ02", "CZ04", "CZ08", "CZ10", "CZ12", "CZ14", "CZ16", 
"DE02", "DE04", "DE06", "DE08", "DE10", "DE12", "DE14", "DE16", 
"DK02", "DK04", "DK06", "DK08", "DK10", "DK12", "DK14", "EE04", 
"EE06", "EE08", "EE10", "EE12", "EE14", "EE16", "ES02", "ES04", 
"ES06", "ES08", "ES10", "ES12", "ES14", "ES16", "FI02", "FI04", 
"FI06", "FI08", "FI10", "FI12", "FI14", "FI16", "FR06", "FR08", 
"FR10", "FR12", "FR14", "FR16", "GB02", "GB04", "GB06", "GB08", 
"GB10", "GB12", "GB14", "GB16", "GR02", "GR04", "GR08", "GR10", 
"HU02", "HU06", "HU08", "HU10", "HU12", "HU14", "HU16", "IE02", 
"IE04", "IE06", "IE08", "IE10", "IE12", "IE14", "IE16", "IT04", 
"IT12", "IT16", "LT10", "LT12", "LT14", "NL02", "NL04", "NL06", 
"NL08", "NL10", "NL12", "NL14", "NL16", "NO14", "PL02", "PL04", 
"PL06", "PL08", "PL10", "PL12", "PL14", "PL16", "PT02", "PT04", 
"PT06", "PT08", "PT10", "PT12", "PT14", "PT16", "SE02", "SE04", 
"SE06", "SE08", "SE10", "SE12", "SE14", "SE16", "SI02", "SI04", 
"SI06", "SI08", "SI10", "SI12", "SI14", "SI16", "SK04", "SK06", 
"SK08", "SK10", "SK12"), class = "factor"), facet = structure(c(1L, 
3L, 1L, 4L, 5L, 3L, 4L, 1L, 1L, 1L, 5L, 5L, 4L, 5L, 3L, 1L, 2L, 
4L, 5L, 2L, 1L, 4L, 2L, 5L, 2L, 3L, 4L, 3L, 2L, 5L, 5L, 4L, 2L, 
5L, 4L, 5L, 3L, 1L, 4L, 5L, 3L, 5L, 4L, 1L, 5L, 2L, 4L, 1L), .Label = c("Intercept", 
"Extreme Left", "Center", "Right", "Extreme Right"), class = "factor"), 
    conf.low = c(1.16824810706745, 0.686215051613965, 0.910277310292764, 
    0.591705078386698, 0.37357342399703, 0.947951001435781, 0.663296044193037, 
    1.18794112232166, 1.06645119085865, 2.33578182814618, 0.580210898576738, 
    0.564235690522211, 0.530859530342114, 0.516191258265551, 
    0.730992343373883, 0.862424540370486, 0.827891784352444, 
    0.427638276259852, 0.275692447335368, 0.829763907986328, 
    0.370078643492081, 0.321852705445509, 0.83550621863293, 0.289836810427436, 
    0.847226120408727, 0.780056160572728, 0.873143885861924, 
    0.869757467125519, 0.615741777890997, 0.649483531741787, 
    0.349657606457465, 0.523294407847395, 0.670109418373736, 
    0.36656743494149, 0.952201390937053, 0.777207016700884, 0.888128473009524, 
    0.397085597526946, 0.479828726362257, 0.614533313431094, 
    0.813336887981082, 0.3129232351085, 0.61435321820328, 0.854801028643867, 
    0.346698059397102, 0.805414039007076, 0.434676644041643, 
    1.07780736338027), conf.high = c(1.70315275860739, 1.06494933995261, 
    1.47855797769819, 1.28312522319126, 1.7272277157504, 1.45743211956315, 
    1.49652679976667, 1.8925358720741, 1.67802460909168, 3.19512520208851, 
    2.44607918797515, 2.25369471581694, 1.05041423643869, 1.8828182806291, 
    1.13872035780431, 1.44368725318228, 1.79353596677755, 1.06769546329854, 
    1.16593171156554, 2.11938292490653, 0.729667639003753, 1.08526995489865, 
    2.05223919950836, 1.29954170985538, 1.51498719434776, 1.15888977865399, 
    1.54095070825389, 1.4292376699955, 1.47610807594453, 2.97492484321718, 
    1.80395225460704, 1.18824770090216, 1.52521060717706, 2.19697554354282, 
    2.01136404338166, 2.37122858469145, 1.29357889999432, 0.740322123703373, 
    1.19469713534712, 3.38237391450413, 1.35145693795059, 1.90755095606211, 
    1.25847381058047, 1.39942645489832, 1.60297301142912, 1.82417470710871, 
    0.907332092210651, 1.68753999308876)), row.names = c(1L, 
9L, 17L, 25L, 33L, 41L, 49L, 57L, 65L, 128L, 136L, 144L, 152L, 
160L, 168L, 176L, 184L, 192L, 200L, 283L, 291L, 299L, 307L, 315L, 
323L, 331L, 339L, 347L, 355L, 363L, 371L, 379L, 442L, 450L, 458L, 
466L, 474L, 512L, 520L, 528L, 536L, 544L, 552L, 640L, 648L, 656L, 
664L, 672L), class = "data.frame")

0 个答案:

没有答案