在ggplot2中没有合并的Dotplot

时间:2019-05-13 10:30:54

标签: r ggplot2

我想从我在ggplot2中看到的一篇文章复制这些情节:

enter image description here

我已经测试了2件事,但是我无法获得想要的结果。

  • 使用geom_dotplot的点图
    我得到了分布形状(类似于小提琴图),但是数据点实际上是装箱在一起的,显示的点不是真实的数据点,这不是我想要的。

    ggplot(t) +
    geom_dotplot(
        aes(x=as.character(dt), y=v_fit, fill=as.character(dt), color=as.character(dt)), 
        binaxis = "y", 
        stackdir = "center", 
        binwidth=0.04) +
    scale_y_continuous(
        limits=c(50, 10000), 
        trans='log10'
    )
    

enter image description here

  • 使用geom_jitter的抖动点图
    另一方面,我有真实的数据点(除了与 jitter 部分引入的x坐标之间的小的随机偏差),但是我失去了分布形状。

    ggplot(t) +
    geom_jitter(aes(x=as.character(dt), y=v_fit, fill=as.character(dt), color=as.character(dt))) +
    scale_y_continuous(
        limits=c(50, 10000), 
        trans='log10'
    )
    

enter image description here

很明显,我想用点图或小提琴图得到形状,但是当我用真实的y坐标绘制实点时。 它应该做的工作与geom_jitter类似,但是只有在点重叠时才在x轴上散布点,这正是上面文章第一幅图所实现的。

感谢您的帮助, 谢谢。


数据

t = structure(list(v_fit = c(534.164528826258, 480.911066257435, 
457.119008832637, 497.634607603821, 1639.64101658328, 163.785146046438, 
1011.08373554375, 446.999460169543, 290.358063262957, 1089.79240143688, 
1224.2829252468, 1721.33107756346, 781.928856744308, 657.206811354693, 
893.006695827087, 903.6824860346, 332.387581297246, 681.295548205955, 
252.822704524236, 3037.70957689832, 809.627297418715, 2671.37397070036, 
946.961614978091, 224.07321623053, 173.30410631272, 62.9012709408904, 
242.118519056607, 464.380594499609, 392.973014449662, 880.471909264493, 
347.510323227536, 1049.57951055953, 700.738563620488, 673.267092514231, 
324.996044204249, 928.998272618453, 590.087284475645, 1116.78735515747, 
257.986635712577, 935.018697108068, 759.482686457198, 478.346163098035, 
686.165166708061, 626.275257027621, 365.1414793875, 584.248372077669, 
506.394755385974, 590.681491206473, 617.483731452587, 299.71275410905, 
2829.60700990855, 649.966105015989, 819.591804251387, 1297.86369222605, 
556.087527129887, 333.590824928921, 677.653760637841, 421.618607534765, 
407.790986178697, 611.314159767955, 613.094957500429, 604.201485791083, 
138.511996845308, 380.053609543318, 1235.56067771288, 294.071026024784, 
750.99859261429, 591.297069400638, 612.249434684164, 893.885105266756, 
247.581567558032, 734.90940476596, 162.826965977393, 525.044144559273, 
535.982182482454, 290.403282850706, 609.087803260785, 350.189963528307, 
622.693010280021, 763.440950581231, 573.770534834755, 393.410239566556, 
494.542048714908, 597.405662994616, 588.851526598432, 356.610720899263, 
747.507512672074, 509.114655408936, 731.288515881844, 659.284738089389, 
130.465909056607, 790.390137180319, 366.74382717758, 200.807270557966, 
233.838177596516, 392.913773176975, 262.570762079857, 280.7069870323, 
886.684621214006, 655.817685376982, 455.884380892248, 1520.61590335575, 
552.942406535928, 1390.90548145761, 904.34648208811, 1007.68084055143, 
548.534329493633, 208.391212139767, 412.319849469212, 110.076899948019, 
1282.65760997612, 2110.47239032506, 175.835127164089, 550.440392451919, 
2059.32190779785, 661.433916099017, 954.097701447349, 1323.55616640051, 
574.524602643465, 1355.63155361186, 869.395072161217, 454.944923329897, 
4615.70368335556, 524.561402228183, 959.894522384859, 141.17722450361, 
430.544144025927, 545.911658968097, 418.538112390949, 830.393908067105, 
536.764393379335, 942.035549658297, 593.819367233046, 690.18517161627, 
785.478409026164, 767.129908019565, 733.682190000261, 939.849595748102, 
716.91223993416, 216.733759768467, 868.791765963341, 146.325973469593, 
197.742919099493, 649.924216609664, 191.556583662582, 844.857518565481, 
543.940973886373, 432.560661307522, 1239.13331853187, 100.57849558528, 
421.810174643153, 759.787611685837, 1055.56336125148, 983.744314492617, 
644.042021706596, 247.998176864075, 734.789535610279, 305.116607839734, 
517.329171641019, 501.008772209776, 192.229142870227, 492.056351157678, 
223.983335647988, 309.025316090484, 417.843613761796, 310.483133501103, 
1880.33667809798, 568.395050209739, 97.3015044460609, 260.459060601823, 
121.930170869655, 495.935212149703, 59.9802350788774, 535.228192887549, 
217.788078431806, 182.294390847443, 462.610866497496, 247.005064836672, 
1359.63073031992, 729.552105268771, 567.557828317892, 471.482102598782, 
286.727278500456, 807.065014868107, 227.055558526809, 636.755730710553, 
651.726240613712, 1541.95154111748, 626.581221078094, 1375.05054916506, 
556.945436491704, 1657.74497627736, 493.458779696477, 278.067644631733, 
152.178341678866, 239.077641434367, 271.205308104755, 281.995672767523, 
240.386440222037, 497.744659195289, 818.572784259719, 1114.78699679558, 
274.776789571777, 676.842592364728, 397.010997951621, 563.828205497513, 
2294.91106273031, 1380.25117606988, 531.382728660938, 633.637191255161, 
252.884550787786, 321.600100104164, 551.151773807781, 269.9493769042, 
99.8661741631295, 376.472303256369, 619.832939989433, 386.71582071092, 
408.792035044728, 261.581073709387, 629.026698242712, 409.854513439682, 
366.071731810129, 459.693448248643, 367.625064253787, 835.114567496367, 
204.110477275887, 1547.94245374155, 668.046934368837, 817.103567204658, 
308.33291215709, 739.030969448431, 584.611919214845, 218.272491704727, 
798.31527342989, 550.486707128114, 1955.91495737727, 293.912886533003, 
434.0496091091, 666.042365077434, 29408.2163088034, 687.063765103289, 
513.952140978438, 576.493607053198, 278.289877557208, 476.239302862408, 
479.529627651816, 275.568875483864, 259.748447679592, 529.020888685875, 
1895.3511581381, 354.81148276155, 266.331229696769, 446.909204346499, 
592.5906572501, 92.7571699217125, 961.233892390465, 523.482796792217, 
498.513253659243, 501.626677114592, 1792.47795608723, 762.974285698485, 
1186.51837171508, 95.8427941733725, 799.090069609835, 637.642003660089, 
804.468799926864, 1332.63199161492, 590.121226155445, 457.716363741657, 
888.363985992005, 181.413113432833, 698.9468288511, 627.346591116243, 
856.735917389738, 396.3171464911, 149.081843475252, 833.211301333243, 
597.031558087907, 182.01664997712, 245.322744307465, 853.34644471126, 
687.292267239194, 607.409531743053, 522.264461655903, 607.26739110733, 
423.962311493566, 1245.7624981884, 959.138739271779, 444.667221192056, 
372.12899313442, 773.07930238258, 653.881671240585, 611.803176472559, 
578.65185477223, 312.437472253213, 250.665136765905, 5124.9928219532, 
359.033680570613, 338.981985412692, 856.273346695504, 468.445356540002, 
333.940882095635, 635.587279001479, 850.626541487562, 843.629839823141, 
398.053477113264, 651.496227485605, 920.56131150571, 880.506017893708, 
699.480443487345, 517.150445920024, 529.589055797541, 408.205115650363, 
1094.41699547992, 482.86095438109, 406.365357379427, 1343.62256701634, 
416.097823792433, 746.433121696645, 1070.90850638035, 292.058690818907, 
365.189050976175, 269.659995654742, 419.95374980672, 1388.23690347487, 
792.7401349636, 811.984612259031, 523.207569321623, 699.156615753862, 
95.0051402044758, 226.530261381035, 1365.01971864399, 1071.70099943982, 
1509.91137610267, 122.904135658141, 420.527842661432, 821.749996812521, 
745.610848465649, 706.49939885984, 249.780967318107, 376.718586018169, 
426.083098093963, 172.114805462957, 531.430777503421, 479.325914161168, 
1505.70693059567, 649.101793750724, 976.556822561157, 510.438501472292, 
835.042215469291, 312.334412394225, 1643.31642719097, 732.084828180039, 
114.869061905047, 456.05315662633, 266.474424604552, 475.791881607864, 
222.237896358623, 223.593057212032, 977.259041075054, 377.153263009509, 
411.338876969078, 311.297762751611, 672.274691038835, 610.165178983753, 
376.754224564282, 477.446901873419, 204.262445691292, 635.626569470454, 
585.873720570179, 343.209935317181, 284.001688541946, 216.413031825842, 
432.319042124359, 416.052771127129, 733.788384598739, 653.529025884919, 
2413.79686134179, 481.846210059161, 376148785.174289, 735.945809173289, 
101.172881680884, 181368555.679022, 52.571334968182, 554.215476524442, 
411.346894085045, 376.517842321494, 291.88224508368, 963.882519700336, 
221.405132326663, 625.485321970204, 479.477464719575, 1013.36335933274, 
716.760561645576, 374.69218469994, 827.066277215869, 664.062228791904, 
686.618511573831, 615.444212384043, 619.491479862961, 366.630578251442, 
255.823959956204, 697.579580009507, 1166.03046981481, 740.462690634954, 
399.10571311819, 2795.11358732495, 415.255254134771, 811.031124617858, 
1008.69471507808, 577.730540631218, 259.504729902056, 361.296263884743, 
285.074845241293, 703.59017248051, 471.348035136559, 336.870483709273, 
543.84241589957, 175.963746448416, 327.629121234582, 146.300594699299, 
211.188739047878, 447.491174029884, 329.880476850023, 265.609052408263, 
1351.65654673844, 591.355609411684, 581.86648303722, 882.774884268772, 
964.571615067412, 407.99777064511, 479.685925643029, 635.187668690822, 
330.249729869612, 424.809409135591, 330.130284002976, 478.822414376712, 
337.231338572741, 571.788983438149, 356.901152406493, 237.737655040249, 
367.280411849323, 165.108966967839, 676.182023797612, 447.272196378831, 
1352.5119988524, 485.92846636334, 55.5565084813041, 324.171149730804, 
809.312444968037, 557.737400594712, 803.068042707372, 968.979052289317, 
541.410626164206, 334.163465693145, 471.208119051988, 353.532055999102, 
659.637299208518, 573.839614986437, 1515.08704266128, 657.864031584348, 
1002.87673857262, 256.339266597473, 807.886802508194, 797.994230150557, 
619.412930352811, 143.056660823437, 828.580181672539, 753.777610822405, 
809.058308346826, 800.559964578277, 708.208331982322, 769.387999501776, 
1288.19204726372, 461.311194234483, 1660.43647841948, 764.624500530856, 
1012.38657101374, 303.11856975823, 354.549471206654, 931.685218852118, 
323.92766619318, 642.695514095366, 876.567768196873, 556.00348836965, 
700.894011942972, 507.837055220993, 509.694391643088, 383.539562280137, 
731.959523393504, 652.597077210002, 291.679030619186, 1144.73768151415, 
601.259699221692, 1883.62718506142, 581.430232442602, 1670.92430193185, 
559.745974859171, 481.422234992742, 361.053296096163, 326.045347330199, 
508.49781792278, 173.845538472718, 372.853125374698, 586.732031306534, 
540.681091490809, 855.310742302584, 569.063436041681, 647.13495703528, 
888.40996322982, 221.797728091217, 564.26584931208, 804.272555277162, 
684.761550106154, 956.245323188892, 993.420030940856, 751.151411843461, 
999.14332604216, 722.914332925105, 3653.8690253218, 305.448467023353, 
796.658789956931, 323.043104397264, 230.219769837322, 808631845.043852, 
147.006580908429, 366.170172594164, 232.380012814077, 731.228841771039, 
230.402914726485, 545.88757395889, 353.277583790557, 1060.41817496005, 
857.940810638936, 551.498144433163, 820.18590680816, 471.934165925577, 
1049.92841877551, 158.816711879692, 920.772444465786, 1078.49309681866, 
140.201739875202, 297.593156354475, 279.564556015568, 551.60777366767, 
693.379543534391, 2354.1162978951, 1148.68364163255, 410.378730766455, 
110.778586436743, 503.62026401093, 538.81701513827, 308.252791361398, 
189.907159629207, 1275.67578485069, 84.1365884726514, 360.833732320545, 
1012.04094357597, 329.516539897343, 515.835013776845, 423.354011568817, 
363.229016712348, 277.644878697274, 460.909985536794, 354.623635939649, 
395.873046141027, 241.501517213687, 607.299641315718, 757.954276952344, 
444.13176170319, 451.0501393012, 523.442797981735, 254.753065247646, 
866.443805122993, 821.092724140609, 353.935925544179, 54168845.4501667, 
720.590179150782, 598.952597175555, 252.642232747448, 388.759816869824, 
101.486073433093, 1154.26701258009, 810.451949088989, 750.966233555031, 
819.564110193907, 284.095318829864, 609.330071401681, 697.160052259421, 
105.584486759691, 244.973956357354, 3435.5529606853, 97.4959104878035
), dt = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,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 8, 8, 8, 8, 8, 8, 8, 8, 8, 
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 
8, 8, 8, 8, 8, 8, 8, 8, 8, 8)), row.names = c(NA, -594L), class = c("tbl_df", "tbl", "data.frame"))

1 个答案:

答案 0 :(得分:3)

您可以尝试使用ggforce软件包中的geom_sina()函数:

library(ggforce)

ggplot(t) +
  geom_sina(aes(as.character(dt), 
                y = v_fit, 
                fill = as.character(dt), 
                colour = as.character(dt))) +
  scale_y_continuous(limits = c(50, 10000), 
                     trans = "log10")

enter image description here

或ggbeeswarm软件包中的geom_beeswarm()

library(ggbeeswarm)
ggplot(t) +
  geom_beeswarm(aes(as.character(dt), 
                y = v_fit, 
                fill = as.character(dt), 
                colour = as.character(dt))) +
  scale_y_continuous(limits = c(50, 10000), 
                     trans = "log10")

enter image description here