Skip to content

Instantly share code, notes, and snippets.

@helske
Last active August 29, 2015 14:25
Show Gist options
  • Save helske/5850c9835ec2c8f17c6d to your computer and use it in GitHub Desktop.
Save helske/5850c9835ec2c8f17c6d to your computer and use it in GitHub Desktop.
Map of disc golf popularity in Finland
library("ggplot2")
library("cowplot")
library("sp")
library("raster")
library("scales")
library("rgeos")
# course information, scraped from fgr.fi
fgr <- read.csv("fgr.csv")
# get map of finland and sub-regions
finland <- getData("GADM", country = "FIN", level = 3)
# combine few old subregions to get official 75 regions
finland <- gUnaryUnion(finland, finland$NAME_3)
# compute holes per sub-regreion
x <- SpatialPointsDataFrame(coords = fgr[,1:2], data = data.frame(holes = fgr$holes),
proj4string = CRS(as.character(finland@proj4string)))
holes_per_area <- unlist(over(finland, x, fn = sum))
names(holes_per_area) <- names(finland)
holes_per_area[is.na(holes_per_area)] <- 9 #Ilomantsi, actually has one course without address
# make new data for ggplot2
finland <- SpatialPolygonsDataFrame(finland,
data = data.frame(id = names(finland), holes = holes_per_area))
dd <- fortify(finland)
dd <- cbind(dd, finland@data[dd$id,])
number_of_holes <- cut(fgr$holes, c(0,8,17,30))
levels(number_of_holes) <- c("less than 9", "9-17", "18 or more")
p <- ggplot(dd, aes(long, lat, group = group)) +
geom_polygon(aes(fill = holes), colour = alpha("black", 1/2), size = 0.2) +
scale_fill_gradientn(colours = rev(topo.colors(200)), name = "Number of holes in sub-region") +
geom_point(data = fgr, aes(x = lon, y = lat, colour = number_of_holes, group = NULL),size = 3) +
scale_colour_manual(values = alpha(c("white", "red", "black"), 0.9),
name = "Number of holes on course") +
theme(axis.ticks = element_blank(), axis.text = element_blank(),
axis.title = element_blank(),
panel.background = element_rect(fill = "white", colour = NA),
panel.grid.minor = element_line(colour = NA),
plot.title = element_text(face = "bold", size = 20),
legend.background = element_rect(colour = 'grey', fill = 'grey', size = 5)) +
ggtitle("Disc golf courses in Finland")
footnote <- paste0("Made with R using ggplot2, raster, rgeos, sp, scales, and cowplot packages.",
"\nCourse information from http://www.fgr.fi\nSub-region boundaries from http://www.gadm.org\n",
"https://en.wikipedia.org/wiki/Sub-regions_of_Finland")
ggdraw(add_sub(p, hjust = 0, x = 0, footnote))
lon lat holes
22.7055 61.2844 9
27.6586 63.0787 12
28.7411 61.877 18
22.7932 60.2618 9
24.1505 67.5982 18
22.3054 60.3884 9
23.3496 63.6992 9
22.7302 60.1703 9
21.6461 63.0877 12
25.348 66.6666 10
21.5096 61.1164 9
23.9351 64.2593 9
25.5374 61.1718 12
26.3376 64.1047 9
27.11 66.32 9
29.1786 63.5339 9
23.0265 59.9798 18
28.296 64.1414 9
22.2739 61.0652 12
22.748 60.7073 6
23.0499 61.4048 12
23.6618 61.5031 9
22.2644 60.3105 9
23.61176 60.81686 9
23.026 60.6963 10
25.6898 61.3005 9
23.007204 62.007388 9
23.1304 60.6564 9
21.5801 63.1325 9
25.2717 63.7408 18
24.8896 60.214 6
24.6739 60.9155 9
23.883 62.5881 17
24.3882 61.0121 12
29.9637 62.4377 10
26.4251 62.3838 9
23.0154 61.2878 18
22.2907 60.3715 9
22.1543 61.3123 9
25.7399 62.2459 6
29.2711 61.9335 18
26.8156 60.939 13
24.606 61.1948 21
22.8275 63.1404 9
26.024691 61.582989 9
24.3365 61.0572 18
22.5612 60.7263 9
28.5241 64.245 18
28.6241 62.4265 9
29.3063 61.9216 9
23.8654 61.4436 9
23.6645 68.3954 9
27.1421 62.3012 9
23.813 64.2317 18
27.4266 66.7163 9
25.53 64.9844 18
23.6594 64.0643 9
25.2977 61.8779 9
29.1081 66.0115 9
25.6849 62.5046 5
26.9305 62.9516 9
23.0275 61.4338 9
25.4747 60.975 9
24.7285 60.4157 9
22.8725 62.67 18
25.8224 63.6445 9
25.7483 65.123 18
24.062 62.6544 9
22.9124 61.336 9
25.63834 60.39801 10
25.6205 60.3539 9
27.2494 67.0187 18
25.800912 62.267741 9
23.3638 60.9256 8
30.153 62.0892 9
26.1045 61.7438 5
27.647706 62.890836 24
28.277 61.4782 9
28.4706 64.682 9
23.0197 61.7769 9
22.610772 62.723017 9
22.3792 60.5082 7
24.001 60.0564 9
24.8004 62.211 18
24.7969 62.2104 9
21.8932 60.3312 9
21.9571 62.118 9
23.9141 61.644 6
21.389 62.2734 18
27.5026 68.6841 18
22.7167 61.7775 18
25.2767 60.8761 6
25.0605 60.4548 9
28.9177 64.8849 9
24.4813 60.1951 6
24.9599 60.5486 9
23.492771 60.801587 12
28.3313 63.0639 18
23.5157 61.5615 24
24.5276 63.8971 10
27.0004 68.898 9
25.0548 60.1513 18
24.3337 60.3877 19
24.3257 64.1247 6
27.2796 61.6663 18
27.7175 64.2031 9
28.8339 61.8659 9
24.5269 65.8209 9
24.9632 63.92 18
27.8732 62.1872 18
26.624 61.98235 14
27.2129 61.2755 9
23.7104 66.313 18
28.7418 61.2012 21
24.2817 61.3349 6
21.7073 62.3072 11
24.2089 60.5369 20
29.7962 62.6044 9
24.7757 62.8885 9
22.5683 62.1376 9
27.2622 61.6805 5
21.23 62.3911 9
27.7704 64.2334 6
22.5166 61.3285 9
29.382 61.7443 12
25.1396 60.3846 18
25.7224 62.1919 9
25.1088 60.5412 9
24.5531 65.7376 9
22.1448 60.4818 4
22.4016 62.614 10
23.0472 60.8534 6
22.3592 60.4141 12
24.6461 62.2118 9
27.4604 68.3472 9
24.7179 60.8915 12
24.6933 60.5065 9
22.1634 61.0778 12
26.0524 61.2114 21
21.5882 60.9625 9
28.285646 66.095288 9
21.78 61.4945 21
29.7546 62.594 9
24.4005 60.1744 13
24.6589 61.3614 4
22.7426 62.4881 9
24.0436 60.3206 9
23.941158 63.904217 10
23.131 63.2675 18
23.4964 61.6165 9
25.0563 60.2383 18
26.7837 60.7566 9
22.3526 61.2537 9
29.8221 63.1638 9
26.706423 67.437164 18
21.8355 62.0272 9
23.0602 62.5535 9
23.7661 62.2392 9
23.1991 63.8283 18
25.5631 64.9026 18
26.532 65.941 9
25.1747 61.5741 18
27.090645 64.343226 9
27.697 62.9734 9
25.772157 62.221534 9
26.618682 63.658552 12
23.5036 62.8195 9
25.303115 62.689676 20
29.1684 66.0013 9
23.6479 61.1622 27
27.8904 62.3469 9
25.3334 62.6621 9
24.5646 63.0353 18
25.6946 62.2569 18
24.1249 60.2737 18
21.57 61.2421 6
22.0417 62.9768 18
25.372229 64.141965 18
21.9651 60.4611 6
23.6494 61.062 18
26.0951 61.8038 9
23.6709 60.0775 18
25.77 66.499 9
20.984043 60.317177 9
23.2495 59.9012 14
23.8685 61.1632 9
25.6471 60.9714 5
25.3273 63.7446 6
26.1997 62.2578 9
22.3472 60.4285 22
27.7473 64.2066 18
25.8797 64.2508 10
22.0992 61.4437 9
27.8657 62.3125 12
27.7797 62.4878 9
24.67 63.5246 9
24.8169 67.787 9
30.0249 63.3254 9
25.6502 64.7602 9
30.3329 62.2208 9
24.5277 64.0675 18
25.7129 62.6143 18
22.9541 59.8388 24
29.4038 62.5246 18
21.4607 60.6906 18
23.7518 60.2568 9
26.5204 62.3306 9
21.3676 60.5304 9
24.448684 60.714219 9
26.3439 63.1886 9
26.2325 60.4103 18
27.3962 63.62 9
23.185 61.6658 6
24.8187 60.4647 18
27.3068 63.1531 9
26.260588 64.352235 10
29.5369 64.1319 9
25.725624 62.268872 6
24.6181 62.037 9
25.2902 60.655 18
26.881 61.4204 9
22.8885 60.5876 9
22.1321 60.5469 18
22.2171 60.5435 9
24.8975 60.1906 16
22.8944 60.7551 18
25.4284 65.0454 18
23.1144 63.8562 9
27.8584 64.4013 6
28.5578 63.5855 11
27.228 61.6989 21
28.7561 61.169 9
25.6696 61.0139 22
25.855 62.4601 5
24.8697 60.1997 9
24.0446 62.5462 13
22.3855 61.8068 9
28.2234 61.0387 18
22.435036 61.039079 6
22.0037 60.6675 18
21.5492 62.3845 9
23.8971 66.9418 18
25.8895 62.2445 7
27.6983 64.2496 6
28.3229 68.8478 4
27.3465 63.4104 9
25.2688 60.39 12
23.5267 61.4829 10
25.4201 64.1425 5
22.0847 60.6024 6
24.2768 60.3258 18
23.8825 60.3993 9
24.8891 60.6487 18
29.0198 66.0664 9
24.5762 60.4998 9
24.663381 60.240345 12
21.3238 62.4637 9
25.739 60.8125 18
22.7333 60.8641 9
24.4262 63.2185 18
25.2815 61.3621 18
23.1522 60.3847 12
22.7222 60.4561 9
25.104 60.3255 11
25.9406 60.9699 18
24.3209 60.3273 9
27.9469 64.6772 9
21.7033 60.8869 6
27.2434 63.561 9
24.7659 60.7309 6
22.1601 60.4517 9
23.1914 61.6507 11
22.3028 60.307 6
29.5087 61.5346 9
24.3519 61.036 12
23.896563 63.3193 18
28.7804 61.1845 9
22.789 63.6054 9
27.7001 62.8364 18
27.5066 67.1116 9
25.0382 63.1323 20
27.2416 63.5178 10
23.1356 60.2092 8
23.899907 64.097967 9
24.9665 63.5796 9
25.1853 62.26 18
25.299419 64.920029 9
25.892 62.435 20
27.0765 62.2895 6
22.6967 63.6704 7
25.5695 63.3647 18
25.1869 63.0123 12
27.6983 65.6298 9
23.6642 61.4563 12
22.271637 61.226252 12
22.0135 61.6855 9
25.3638 60.4784 9
23.1362 61.0917 9
24.6981 60.1766 10
24.2714 64.4702 12
23.1258 62.1852 9
26.3237 64.0913 9
24.8097 62.670486 9
24.4918 64.6781 18
27 65.3636 9
24.7523 60.5271 18
24.0422 61.4617 9
25.3456 64.8085 18
25.159 62.117 9
28.309408 62.064 18
24.442515 61.02229 9
23.5279 61.4681 6
24.5696 65.0342 9
25.6507 64.5172 9
26.5106 65.9247 9
24.7473 64.0049 9
26.8431 62.6157 18
28.5034 61.1109 18
22.7537 61.1813 9
27.5571 62.754 9
25.6897 62.1083 18
28.2107 64.5037 9
24.9887 60.4036 18
21.7257 63.0981 18
24.6994 60.7246 18
24.0615 60.2751 9
24.349 61.6609 9
27.1467 60.5798 18
29.1206 66.1651 9
29.1439 66.1677 18
27.109 69.0682 6
24.87 60.6514 19
28.3115 62.1235 9
21.9847 62.6654 18
28.7694 66.7593 9
28.3976 64.1362 10
28.1084 61.047 9
24.5018 61.3858 21
25.9621 62.4118 5
24.9952 60.2377 4
27.6988 61.1943 9
25.8378 63.0829 9
29.1987 62.1805 9
21.6851 63.1156 9
22.2341 60.9902 9
21.8391 61.8875 19
27.6727 63.0741 7
24.983 60.273 18
25.1253 65.6947 9
25.0288 60.3057 10
24.2179 60.1355 9
23.3268 59.9281 18
25.3377 60.2988 12
27.5468 63.6687 9
24.2571 67.5501 18
28.369 61.7836 18
23.3838 60.1204 18
27.1017 62.6256 18
22.056 60.4868 18
21.6471 63.0785 5
22.2238 60.3897 9
27.6067 65.6346 18
24.753 60.1961 3
28.1972 65.5657 27
24.8468 60.2131 18
23.7619 60.8122 9
29.0762 61.8077 9
27.6213 63.0722 18
29.3517 61.4346 9
24.6213 60.8099 9
27.8233 64.4083 12
28.9519 61.8466 6
26.6836 63.0029 9
30.3405 62.2362 6
21.5637 60.5014 9
24.2465 63.7654 9
26.086 62.0934 9
25.8475 66.4753 18
22.8335 62.7618 9
24.1422 65.8525 9
25.3677 65.1721 9
22.575963 61.454503 9
25.748924 62.254904 9
23.7936 61.3889 6
25.0322 60.3905 12
21.4053 60.8069 9
22.1848 62.4266 25
28.2462 64.7401 18
24.9772 63.3649 10
21.8879 61.4321 9
21.5928 61.128 18
23.7882 60.7228 9
26.0081 61.1129 9
22.2611 60.4417 9
26.7094 60.8725 9
23.068 63.0945 9
28.7804 61.1845 9
26.4244 64.7635 18
29.8496 62.621 18
26.8768 64.567 18
21.8646 61.4669 4
24.0287 61.2884 9
24.8917 63.4339 10
22.6113 60.9896 28
29.0045 62.7317 18
21.8287 62.4268 9
23.116 61.1116 5
23.4079 59.9901 18
21.6614 60.6871 18
24.4332 60.2665 18
26.4037 62.935 9
23.673702 61.262216 9
22.7519 60.0676 9
22.1976 60.4867 9
22.0152 60.3799 9
27.0017 63.7495 9
23.7983 61.4758 9
25.8947 62.3714 9
22.4839 61.8143 18
24.509231 62.02295 4
27.717 64.2106 18
25.26 65.1365 18
27.3449 61.7031 3
25.7642 62.1576 9
28.2858 64.1405 9
27.69531 62.978893 9
25.697345 62.25628 9
24.5293 61.2036 9
24.7478 60.8057 9
22.3789 62.9735 18
23.6699 66.3182 5
21.522 61.567 11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment