Last active
November 12, 2018 13:50
-
-
Save hrbrmstr/e3d0dc87eaacf7bbece7 to your computer and use it in GitHub Desktop.
Revisions
-
hrbrmstr revised this gist
Sep 26, 2014 . No changes.There are no files selected for viewing
-
hrbrmstr revised this gist
Sep 26, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ library(rgeos) library(rgdal) # needs gdal > 1.11.0 library(ggplot2) # map theme devtools::source_gist("https://gist.github.com/hrbrmstr/33baa3a79c5cfef0f6df") map = readOGR("readme-swiss.json", "cantons") -
hrbrmstr revised this gist
Sep 26, 2014 . No changes.There are no files selected for viewing
-
hrbrmstr revised this gist
Sep 20, 2014 . 1 changed file with 3 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,8 @@ library(rgeos) library(rgdal) # needs gdal > 1.11.0 library(ggplot2) devtools::source_gist("https://gist.github.com/hrbrmstr/33baa3a79c5cfef0f6df") map = readOGR("readme-swiss.json", "cantons") map_df <- fortify(map) @@ -22,12 +24,7 @@ gg <- gg + geom_map(data=map_df, map=map_df, gg <- gg + geom_text(data=centers, aes(label=canton, x=x, y=y), size=3) gg <- gg + coord_map() gg <- gg + labs(x="", y="", title="Swiss Cantons") gg <- gg + theme_map() gg ggsave("cantons.svg", gg, width=9, height=6) -
hrbrmstr revised this gist
Sep 20, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ library(rgeos) library(rgdal) # needs gdal > 1.11.0 library(ggplot2) map = readOGR("readme-swiss.json", "cantons") map_df <- fortify(map) # create mapping for id # to name since "region=" won't work @@ -30,4 +30,4 @@ gg <- gg + theme(axis.ticks=element_blank()) gg <- gg + theme(axis.text=element_blank()) gg ggsave("cantons.svg", gg, width=9, height=6) -
hrbrmstr revised this gist
Sep 20, 2014 . 1 changed file with 5 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,30 +1,19 @@ library(rgeos) library(rgdal) # needs gdal > 1.11.0 library(ggplot2) map = readOGR("/Users/bob/Desktop/readme-swiss.json", "cantons") map_df <- fortify(map) # create mapping for id # to name since "region=" won't work dat <- data.frame(id=0:(length(map@data$name)-1), canton=map@data$name) map_df <- merge(map_df, dat, by="id") # find canton centers centers <- data.frame(gCentroid(map, byid=TRUE)) centers$canton <- dat$canton # make a map! gg <- ggplot() gg <- gg + geom_map(data=map_df, map=map_df, aes(map_id=id, x=long, y=lat, group=group), @@ -41,4 +30,4 @@ gg <- gg + theme(axis.ticks=element_blank()) gg <- gg + theme(axis.text=element_blank()) gg ggsave("/Users/bob/Desktop/cantons.svg", gg, width=9, height=6) -
hrbrmstr revised this gist
Sep 20, 2014 . No changes.There are no files selected for viewing
-
hrbrmstr revised this gist
Sep 20, 2014 . No changes.There are no files selected for viewing
-
hrbrmstr revised this gist
Sep 20, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,6 +21,7 @@ dat map_df <- merge(map_df, dat, by="id") # get and label canton centers centers <- data.frame(gCentroid(map, byid=TRUE)) centers$canton <- dat$canton -
hrbrmstr revised this gist
Sep 20, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@  -
hrbrmstr revised this gist
Sep 20, 2014 . 1 changed file with 0 additions and 557 deletions.There are no files selected for viewing
-
hrbrmstr created this gist
Sep 20, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ library(rvest) library(dplyr) library(httr) # >0.5 library(tidyr) library(gpclib) library(rgeos) library(sp) library(maptools) library(rgdal) # needs gdal > 1.11.0 library(ggplot2) library(reshape2) library(gridExtra) map = readOGR("readme-swiss.json", "cantons") map_df <- fortify(map) dat <- data.frame(id=0:(length(map@data$name)-1), canton=map@data$name) dat$color <- "blue" dat[2,]$color <- "red" dat map_df <- merge(map_df, dat, by="id") centers <- data.frame(gCentroid(map, byid=TRUE)) centers$canton <- dat$canton gg <- ggplot() gg <- gg + geom_map(data=map_df, map=map_df, aes(map_id=id, x=long, y=lat, group=group), color="#ffffff", fill="#bbbbbb", size=0.25) # gg <- gg + geom_point(data=centers, aes(x=x, y=y)) gg <- gg + geom_text(data=centers, aes(label=canton, x=x, y=y), size=3) gg <- gg + coord_map() gg <- gg + labs(x="", y="", title="Swiss Cantons") gg <- gg + theme_bw() gg <- gg + theme(panel.grid=element_blank()) gg <- gg + theme(legend.position="none") gg <- gg + theme(panel.border=element_blank()) gg <- gg + theme(axis.ticks=element_blank()) gg <- gg + theme(axis.text=element_blank()) gg ggsave("cantons.svg", gg, width=9, height=6) LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed.