Skip to content

Instantly share code, notes, and snippets.

@GuangchuangYu
Last active June 21, 2018 03:59
Show Gist options
  • Save GuangchuangYu/22d6b8cc5e43f7f537c931d53d0f78b0 to your computer and use it in GitHub Desktop.
Save GuangchuangYu/22d6b8cc5e43f7f537c931d53d0f78b0 to your computer and use it in GitHub Desktop.
d = structure(list(x = c(516.362976074219, 514.883316040039, 510.306549072266,
502.721382141113, 492.303680419922, 479.293769836426, 463.977825164795,
446.675720214844, 427.74100112915, 407.568737030029, 386.590072631836,
365.25927734375, 344.028457641602, 323.352523803711, 303.678215026855,
285.42236328125, 268.959743499756, 254.630310058594, 242.738302230835,
233.550735473633, 227.284624099731, 224.07541847229, 223.949848175049,
226.633100509644, 232.021848678589, 240.107601165771, 248.467231750488,
256.632625579834, 264.798046112061, 272.827682495117, 279.170124053955,
284.358814239502, 288.348812103271, 291.169918060303, 292.902908325195,
293.650428771973, 293.608024597168, 292.990119934082, 291.361457824707,
287.676113128662, 280.439525604248, 270.934875488281, 261.897472381592,
258.723621368408, 270.276329040527, 288.330253601074, 308.458564758301,
329.375465393066, 350.618808746338, 371.97403717041, 393.31957244873,
414.52339553833, 435.341442108154, 455.228332519531, 472.58226776123,
481.987930297852, 476.526496887207, 467.307327270508, 462.520275115967,
458.842247009277, 455.164245605469, 451.486190795898, 447.80818939209,
446.458198547363, 447.442893981934, 449.439628601074, 452.548511505127,
456.839317321777, 462.32555770874, 468.939407348633, 476.515068054199,
484.800224304199, 493.478713989258, 501.986465454102, 509.603515625,
514.278762817383, 516.298248291016, 387.176815032959, 408.00936126709,
427.767009735107, 445.898105621338, 461.91134262085, 475.369995117188,
485.890129089355, 493.152725219727, 477.113906860352, 462.797077178955,
459.514331817627, 455.897159576416, 439.701515197754, 420.848827362061,
408.802223205566, 398.452747344971, 387.741474151611, 376.255550384521,
364.007873535156, 350.690586090088, 332.509796142578, 312.238864898682,
301.611946105957, 304.793193817139, 303.088668823242, 288.39319229126,
267.585479736328, 250.549816131592, 243.631059646606, 242.533597946167,
244.87748336792, 250.744853973389, 259.973182678223, 272.279632568359,
287.303714752197, 304.629878997803, 323.789356231689, 344.254844665527,
365.446170806885, 464.608467102051, 473.297584533691, 464.30456161499,
444.207920074463, 427.700626373291, 426.857616424561, 442.297729492188,
263.71858215332, 284.912338256836, 304.317321777344, 318.419914245605,
328.212421417236, 337.592823028564, 345.484672546387, 351.732158660889,
356.1584815979, 358.57063293457, 358.762439727783, 356.7121925354,
352.589427947998, 346.371128082275, 338.292278289795, 328.874866485596,
318.898456573486, 312.478576660156, 312.489204406738, 311.69690322876,
309.94877243042, 307.162487030029, 303.275588989258, 298.263324737549,
292.154426574707, 285.048522949219, 277.123695373535, 268.633380889893,
461.968299865723, 445.43302154541, 425.339290618896, 404.379558563232,
383.103744506836, 361.741760253906, 340.431499481201, 319.36994934082,
298.991859436035, 280.949043273926, 281.186645507812, 290.475028991699,
299.763919830322, 312.183910369873, 332.503868103027, 353.619064331055,
374.965293884277, 396.246715545654, 417.101852416992, 436.223117828369,
444.39022064209, 453.929344177246, 462.847972869873, 427.658355712891,
428.498908996582, 430.440368652344, 418.542819976807, 397.970947265625,
376.729446411133, 355.381721496582, 334.289516448975, 314.407939910889,
317.541389465332, 325.987884521484, 335.72057723999, 345.726867675781,
355.141929626465, 363.314613342285, 369.813667297363, 374.416896820068,
377.09105682373, 377.790405273438, 376.387088775635, 373.037212371826,
367.902702331543, 361.136138916016, 352.877285003662, 343.250122070312,
332.367950439453, 321.086116790771, 331.623260498047, 346.121215820312,
358.544544219971, 370.158641815186, 380.956192016602, 391.639347076416,
403.362873077393, 417.466106414795, 435.677391052246, 456.77322769165,
450.984951019287, 444.400127410889, 438.877117156982, 434.47562789917,
431.19312286377, 428.981563568115, 427.765140533447, 487.115097045898,
473.471954345703, 476.456642150879, 478.993789672852, 491.433967590332,
497.212257385254, 494.350776672363), y = c(201.768993377686,
180.472791671753, 159.621606826782, 139.66711807251, 121.033740997314,
104.107919692993, 89.2362775802612, 76.7312717437744, 66.8719973564148,
59.8863501548767, 55.9347076416016, 55.0761499404907, 57.3077363967896,
62.6200408935547, 70.9052004814148, 81.9710245132446, 95.5624771118164,
111.387018203735, 129.115828514099, 148.385354995728, 168.792444229126,
189.897466659546, 211.246006011963, 232.42985534668, 253.087924957275,
272.859752655029, 292.522018432617, 312.266902923584, 332.011920928955,
351.80834197998, 372.209476470947, 392.933795928955, 413.921859741211,
435.099086761475, 456.393245697021, 477.745269775391, 499.111419677734,
520.468383789062, 541.769218444824, 562.798751831055, 582.868743896484,
602.004188537598, 621.36270904541, 641.914154052734, 659.50414276123,
670.790008544922, 677.886352539062, 682.193740844727, 684.425567626953,
684.990921020508, 684.148872375488, 681.570869445801, 676.816741943359,
669.082626342773, 656.78685760498, 638.043464660645, 617.75984954834,
598.486404418945, 577.807052612305, 556.758934020996, 535.711029052734,
514.662696838379, 493.614791870117, 472.379112243652, 451.036647796631,
429.765079498291, 408.628147125244, 387.699604034424, 367.052028656006,
346.737331390381, 326.760265350342, 307.065902709961, 287.540996551514,
267.942176818848, 247.996780395508, 227.163646697998, 205.906698226929,
75.0109286308289, 79.642560005188, 87.7098073959351, 98.9673013687134,
113.076683044434, 129.640226364136, 148.209089279175, 168.276504516602,
173.788299560547, 188.955722808838, 209.960195541382, 231.006458282471,
238.242204666138, 247.822944641113, 265.206520080566, 250.524421691895,
232.037990570068, 214.022531509399, 196.517471313477, 179.817142486572,
169.380788803101, 174.097478866577, 191.988422393799, 212.814920425415,
233.754264831543, 248.644031524658, 251.182193756104, 239.11757850647,
219.272010803223, 197.953578948975, 176.740369796753, 156.221876144409,
136.978845596313, 119.542458534241, 104.384267807007, 91.9224805831909,
82.5216379165649, 76.4701375961304, 73.9388446807861, 261.658882141113,
280.420513153076, 299.038269042969, 303.902786254883, 291.446800231934,
270.784324645996, 257.024543762207, 269.620239257812, 269.632095336914,
261.046211242676, 245.225955963135, 249.196380615234, 268.387260437012,
288.236526489258, 308.662414550781, 329.558032989502, 350.780361175537,
372.135269165039, 393.39538192749, 414.350841522217, 434.784019470215,
454.557849884033, 473.733055114746, 492.628974914551, 497.817985534668,
476.452476501465, 455.101947784424, 433.808349609375, 412.625888824463,
391.617530822754, 370.84981918335, 350.377681732178, 330.228889465332,
310.387660980225, 290.780429840088, 639.68424987793, 652.74153137207,
659.910400390625, 663.994979858398, 665.876304626465, 666.046989440918,
664.595420837402, 661.064231872559, 654.721015930176, 643.539558410645,
624.342430114746, 605.103004455566, 585.863258361816, 578.963447570801,
585.449310302734, 588.620010375977, 589.259330749512, 587.487915039062,
582.937477111816, 575.159996032715, 594.883865356445, 614.003234863281,
633.416976928711, 505.482406616211, 526.830184936523, 548.104904174805,
562.54411315918, 568.162879943848, 570.344184875488, 569.861557006836,
566.579452514648, 558.997062683105, 539.699424743652, 520.08145904541,
501.064308166504, 482.186653137207, 463.008270263672, 443.271636962891,
422.923667907715, 402.065006256104, 380.874160766602, 359.527824401855,
338.21537399292, 317.11967086792, 296.385417938232, 276.124153137207,
256.42244720459, 237.350902557373, 218.967317581177, 200.873739242554,
188.650588989258, 204.0837059021, 221.465625762939, 239.398866653442,
257.832733154297, 276.334144592285, 294.190948486328, 310.182796478271,
321.101070404053, 322.575496673584, 341.145454406738, 361.470993041992,
382.109970092773, 403.016002655029, 424.126979827881, 445.375343322754,
466.706539154053, 254.720432281494, 244.763782501221, 224.632574081421,
203.42840385437, 191.015356063843, 210.293874740601, 231.450967788696
), flag = c("co", "pe", "en", "es", "ru", "sn", "br", "ar", "tn",
"kr", "hr", "ch", "hr", "be", "co", "en", "pe", "br", "dk", "se",
"kr", "uy", "au", "se", "pe", "co", "uy", "be", "en", "eg", "is",
"co", "au", "kr", "eg", "br", "ir", "ar", "uy", "hr", "be", "cr",
"jp", "ir", "eg", "pl", "is", "ma", "hr", "co", "mx", "de", "pl",
"fr", "pt", "ir", "be", "jp", "en", "be", "pt", "co", "tn", "ng",
"au", "se", "se", "br", "ch", "eg", "sa", "au", "ma", "jp", "sa",
"de", "ru", "eg", "sn", "tn", "en", "ar", "ma", "ma", "ir", "pt",
"hr", "br", "dk", "au", "ng", "ir", "uy", "tn", "cr", "es", "mx",
"ir", "ru", "jp", "pa", "ch", "ma", "tn", "ma", "co", "pl", "se",
"is", "ma", "se", "br", "es", "pa", "de", "ch", "cr", "en", "ar",
"hr", "rs", "ma", "be", "ma", "rs", "kr", "en", "se", "en", "au",
"pa", "kr", "fr", "pa", "sn", "ru", "pl", "pe", "uy", "rs", "uy",
"pl", "ru", "au", "kr", "mx", "pl", "ar", "tn", "br", "sn", "ar",
"be", "ru", "ng", "fr", "hr", "kr", "kr", "pa", "uy", "ng", "ma",
"pe", "de", "ar", "sa", "is", "jp", "br", "rs", "ng", "rs", "ng",
"tn", "en", "cr", "cr", "ch", "sn", "de", "sa", "co", "ar", "au",
"is", "pa", "eg", "en", "ru", "pe", "kr", "fr", "is", "ng", "ch",
"hr", "cr", "tn", "fr", "ru", "cr", "br", "eg", "be", "kr", "sn",
"is", "au", "is", "sa", "rs", "kr", "pl", "sa", "be", "ng", "hr",
"en", "br", "ma", "ng", "ma", "rs", "de")), row.names = c(NA,
-225L), class = "data.frame")
require(ggplot2)
require(ggimage) # v >= 0.1.7
p2 = ggplot(d, aes(x, y)) + geom_point() + scale_y_reverse() + xlab(NULL) + ylab(NULL) +
geom_image(image="http://guangchuangyu.github.io/blog_images/biobabble.jpg", x=250, y=-500, size=.2, asp=.5) +
labs(title="中年狗不配看世界杯", subtitle="熬夜已然吃不消!") +
labs(caption="学ggplot2画图\n请扫码关注公众号\nbiobabble") +
theme(plot.title=element_text(family="STHeiti"), plot.subtitle=element_text(family="STHeiti"),
plot.caption=element_text(family="STHeiti", hjust=0)) + coord_equal()
p1 = ggplot(d, aes(x, y)) + geom_worldcup2018(aes(image=flag), asp=.5) +
scale_y_reverse() + xlab(NULL) + ylab(NULL) + coord_equal()
pp = cowplot::plot_grid(p2, p1, ncol=2)
print(pp)
@GuangchuangYu
Copy link
Author

worldcup2018

@GuangchuangYu
Copy link
Author

# try http if https is not supported
source("https://gist.githubusercontent.com/GuangchuangYu/22d6b8cc5e43f7f537c931d53d0f78b0/raw/52d22fb05f6ec10c0839bde22cf1eb37042b6978/worldcup2018.R")

This command will plot the figure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment