├── NEWS.md ├── LICENSE ├── data ├── ssm.rda ├── maple.rda ├── milk.rda ├── usa_abb.rda ├── canada_abb.rda └── mexico_abb.rda ├── tests ├── testthat.R └── testthat │ ├── testusa.R │ ├── testcanada.R │ └── testmexico.R ├── .gitignore ├── .Rbuildignore ├── NAMESPACE ├── .travis.yml ├── man ├── canada_abb.Rd ├── mexico_abb.Rd ├── usa_abb.Rd ├── milk.Rd ├── ssm.Rd ├── maple.Rd ├── miniusa.Rd ├── minimexico.Rd └── minicanada.Rd ├── cran-comments.md ├── DESCRIPTION ├── R ├── plotbox.R ├── data.R ├── minicanada.R ├── minimexico.R └── miniusa.R └── README.md /NEWS.md: -------------------------------------------------------------------------------- 1 | # minimap 0.1 2 | 3 | - First release. 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2016 2 | COPYRIGHT HOLDER: Sean Kross 3 | -------------------------------------------------------------------------------- /data/ssm.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seankross/minimap/HEAD/data/ssm.rda -------------------------------------------------------------------------------- /data/maple.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seankross/minimap/HEAD/data/maple.rda -------------------------------------------------------------------------------- /data/milk.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seankross/minimap/HEAD/data/milk.rda -------------------------------------------------------------------------------- /data/usa_abb.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seankross/minimap/HEAD/data/usa_abb.rda -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(minimap) 3 | 4 | test_check("minimap") -------------------------------------------------------------------------------- /data/canada_abb.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seankross/minimap/HEAD/data/canada_abb.rda -------------------------------------------------------------------------------- /data/mexico_abb.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seankross/minimap/HEAD/data/mexico_abb.rda -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | minimap.Rproj 5 | .DS_Store 6 | *.html 7 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.travis\.yml$ 4 | ^NEWS.md$ 5 | ^.*.html$ 6 | ^cran-comments\.md$ 7 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(minicanada) 4 | export(minimexico) 5 | export(miniusa) 6 | importFrom(graphics,par) 7 | importFrom(graphics,plot) 8 | importFrom(graphics,rect) 9 | importFrom(graphics,text) 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: R 2 | cache: packages 3 | sudo: false 4 | 5 | r_github_packages: 6 | - jimhester/covr 7 | 8 | after_success: 9 | - Rscript -e 'covr::codecov()' 10 | 11 | notifications: 12 | email: 13 | on_success: always 14 | on_failure: always 15 | -------------------------------------------------------------------------------- /man/canada_abb.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{canada_abb} 5 | \alias{canada_abb} 6 | \title{Postal Abbreviations for Canada} 7 | \format{An object of class \code{character} of length 13.} 8 | \usage{ 9 | canada_abb 10 | } 11 | \description{ 12 | Postal Abbreviations for Canada 13 | } 14 | \examples{ 15 | \dontrun{ 16 | canada_abb 17 | } 18 | } 19 | \keyword{datasets} 20 | 21 | -------------------------------------------------------------------------------- /man/mexico_abb.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{mexico_abb} 5 | \alias{mexico_abb} 6 | \title{Postal Abbreviations for Mexico} 7 | \format{An object of class \code{character} of length 32.} 8 | \usage{ 9 | mexico_abb 10 | } 11 | \description{ 12 | Postal Abbreviations for Mexico 13 | } 14 | \examples{ 15 | \dontrun{ 16 | mexico_abb 17 | } 18 | } 19 | \keyword{datasets} 20 | 21 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## Release summary 2 | 3 | This is the first attempted CRAN release of minimap. 4 | 5 | ## Test environments 6 | 7 | * local OSX Yosemite install, R 3.2.3 8 | * Ubuntu 12.04 (on travis-ci), R 3.2.3 9 | * win-builder (devel and release) 10 | 11 | ## R CMD check results 12 | 13 | There were no ERRORs or WARNINGs. 14 | 15 | There is 1 NOTE: 16 | 17 | * Possibly mis-spelled words in DESCRIPTION: 18 | choropleth (7:52) 19 | 20 | To my knowledge this is the correct spelling. -------------------------------------------------------------------------------- /man/usa_abb.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{usa_abb} 5 | \alias{usa_abb} 6 | \title{Postal Abbreviations for The United States of America} 7 | \format{An object of class \code{character} of length 51.} 8 | \usage{ 9 | usa_abb 10 | } 11 | \description{ 12 | Postal Abbreviations for The United States of America 13 | } 14 | \examples{ 15 | \dontrun{ 16 | usa_abb 17 | } 18 | } 19 | \keyword{datasets} 20 | 21 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: minimap 2 | Type: Package 3 | Title: Create Tile Grid Maps 4 | Version: 0.1.0 5 | Date: 2016-02-17 6 | Authors@R: person("Sean", "Kross", , "sean@seankross.com", c("aut", "cre")) 7 | Description: Create tile grid maps, which are like choropleth maps except each 8 | region is represented with equal visual space. 9 | Depends: 10 | R (>= 3.1.0), 11 | graphics 12 | Suggests: 13 | testthat 14 | License: MIT + file LICENSE 15 | LazyData: TRUE 16 | Encoding: UTF-8 17 | URL: http://github.com/seankross/minimap 18 | RoxygenNote: 5.0.1 19 | -------------------------------------------------------------------------------- /man/milk.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{milk} 5 | \alias{milk} 6 | \title{Monthly milk production in Canada} 7 | \format{A data frame with columns: 8 | \describe{ 9 | \item{Year}{A value between 1976 and 2015.} 10 | \item{Month}{A value between 1 and 12.} 11 | \item{Region}{Postal code abbreviation for territory or province.} 12 | \item{Kiloliters}{Milk sold off farms in kiloliters.} 13 | }} 14 | \source{ 15 | Statistics Canada. Table 003-0011 - Milk production and utilization, 16 | monthly. \url{http://www5.statcan.gc.ca/cansim/} 17 | } 18 | \usage{ 19 | milk 20 | } 21 | \description{ 22 | Monthly milk production in Canada 23 | } 24 | \examples{ 25 | \dontrun{ 26 | milk 27 | } 28 | } 29 | \keyword{datasets} 30 | 31 | -------------------------------------------------------------------------------- /man/ssm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{ssm} 5 | \alias{ssm} 6 | \title{Same sex marriage in the US} 7 | \format{A data frame with columns: 8 | \describe{ 9 | \item{State}{State Abbreviation} 10 | \item{Status}{Legal status. Either \code{bbs} meaning banned by statute, 11 | \code{nl} meaning not legal, \code{legal}, \code{bbca} meaning banned by 12 | constitutional ammendment, or \code{dis} meaning disputed.} 13 | \item{Year}{Year status went into effect.} 14 | }} 15 | \source{ 16 | \url{http://www.nytimes.com/interactive/2015/03/04/us/gay-marriage-state-by-state.html} 17 | } 18 | \usage{ 19 | ssm 20 | } 21 | \description{ 22 | Changes in the legality of same sex marriage in the United States over time. 23 | } 24 | \examples{ 25 | \dontrun{ 26 | ssm 27 | } 28 | } 29 | \keyword{datasets} 30 | 31 | -------------------------------------------------------------------------------- /tests/testthat/testusa.R: -------------------------------------------------------------------------------- 1 | context("Test miniusa()") 2 | 3 | test_that("The USA is drawn correctly", { 4 | expect_silent(miniusa(usa_abb, 1:51)) 5 | expect_silent(miniusa(usa_abb, 1:51, border_colors = rep("red", 51), 6 | state_names = FALSE)) 7 | expect_silent(miniusa(usa_abb, rep("black", 51), border_colors = rep("white", 51), 8 | state_name_colors = rep("yellow", 51), state_name_cex = .5, 9 | font = "serif")) 10 | }) 11 | 12 | test_that("miniusa() throws appropriate errors", { 13 | expect_error(miniusa(c(usa_abb[-1], "DC"), 1:51)) 14 | expect_error(miniusa(usa_abb[1:10], 1:51)) 15 | expect_error(miniusa(usa_abb, 1:10)) 16 | expect_error(miniusa(usa_abb, 1:51, border_colors = 1:10)) 17 | expect_error(miniusa(usa_abb, 1:51, state_names = NA)) 18 | expect_error(miniusa(usa_abb, 1:51, state_name_colors = 1:10)) 19 | }) -------------------------------------------------------------------------------- /man/maple.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{maple} 5 | \alias{maple} 6 | \title{Production and farm value of maple products in Canada} 7 | \format{A data frame with columns: 8 | \describe{ 9 | \item{Year}{A value between 1924 and 2015.} 10 | \item{Syrup}{Maple products expressed as syrup, total in thousands of gallons.} 11 | \item{CAD}{Gross value of maple products in thousands of Canadian dollars.} 12 | \item{Region}{Postal code abbreviation for territory or province.} 13 | }} 14 | \source{ 15 | Statistics Canada. Table 001-0008 - Production and farm value of 16 | maple products, annual. \url{http://www5.statcan.gc.ca/cansim/} 17 | } 18 | \usage{ 19 | maple 20 | } 21 | \description{ 22 | Production and farm value of maple products in Canada 23 | } 24 | \examples{ 25 | \dontrun{ 26 | maple 27 | } 28 | } 29 | \keyword{datasets} 30 | 31 | -------------------------------------------------------------------------------- /tests/testthat/testcanada.R: -------------------------------------------------------------------------------- 1 | context("Test minicanada()") 2 | 3 | test_that("Canada is drawn correctly", { 4 | expect_silent(minicanada(canada_abb, 1:13)) 5 | expect_silent(minicanada(canada_abb, 1:13, border_colors = rep("red", 13), 6 | pt_names = FALSE)) 7 | expect_silent(minicanada(canada_abb, rep("black", 13), border_colors = rep("white", 13), 8 | pt_name_colors = rep("yellow", 13), pt_name_cex = .5, 9 | font = "serif")) 10 | }) 11 | 12 | test_that("minicanada() throws appropriate errors", { 13 | expect_error(minicanada(c(canada_abb[-1], "NU"), 1:13)) 14 | expect_error(minicanada(canada_abb[1:10], 1:13)) 15 | expect_error(minicanada(canada_abb, 1:10)) 16 | expect_error(minicanada(canada_abb, 1:13, border_colors = 1:10)) 17 | expect_error(minicanada(canada_abb, 1:13, pt_names = NA)) 18 | expect_error(minicanada(canada_abb, 1:13, pt_name_colors = 1:10)) 19 | }) -------------------------------------------------------------------------------- /tests/testthat/testmexico.R: -------------------------------------------------------------------------------- 1 | context("Test minimexico()") 2 | 3 | test_that("Mexico is drawn correctly", { 4 | expect_silent(minimexico(mexico_abb, 1:32)) 5 | expect_silent(minimexico(mexico_abb, 1:32, border_colors = rep("red", 32), 6 | estados_names = FALSE)) 7 | expect_silent(minimexico(mexico_abb, rep("black", 32), border_colors = rep("white", 32), 8 | estados_name_colors = rep("yellow", 32), estados_name_cex = .5, 9 | font = "serif")) 10 | }) 11 | 12 | test_that("minimexico() throws appropriate errors", { 13 | expect_error(minimexico(c(mexico_abb[-1], "DIF"), 1:32)) 14 | expect_error(minimexico(mexico_abb[1:10], 1:32)) 15 | expect_error(minimexico(mexico_abb, 1:10)) 16 | expect_error(minimexico(mexico_abb, 1:32, border_colors = 1:10)) 17 | expect_error(minimexico(mexico_abb, 1:32, estados_names = NA)) 18 | expect_error(minimexico(mexico_abb, 1:32, estados_name_colors = 1:10)) 19 | }) -------------------------------------------------------------------------------- /R/plotbox.R: -------------------------------------------------------------------------------- 1 | # @param x X coordinates of boxes to be plotted. 2 | # @param y Y coordinates of boxes to be plotted. 3 | # @param color Color of each box. 4 | # @param n_xboxes Width of plot. 5 | # @param n_yboxes Height of plot. 6 | # @param text_ Text in each box. (Optional) 7 | # @param text_col Color of text in each box. (Optional) 8 | 9 | #' @importFrom graphics par plot rect text 10 | plotbox <- function(x, y, color, border_col, n_xboxes, n_yboxes, 11 | text_ = NULL, text_col, text_cex = 1, text_font = NULL){ 12 | # Store old par 13 | old_xaxs <- par()$xaxs 14 | old_yaxs <- par()$yaxs 15 | 16 | # Make X and Y axis have precise ends 17 | par(xaxs = "i", yaxs = "i") 18 | 19 | plot(0,0, col = "white", xlim = c(0, n_xboxes), ylim = c(0, n_yboxes), 20 | bty = "n", xaxt = "n", yaxt = "n", ann = FALSE, asp = 1) 21 | 22 | for(i in 1:length(x)){ 23 | rect(x[i], y[i], x[i] + 1, y[i] + 1, 24 | col = color[i], 25 | border = border_col[i]) 26 | if(!is.null(text_)){ 27 | text(x[i] + .5, y[i] + .5, text_[i], col = text_col[i], cex = text_cex, 28 | family = text_font) 29 | } 30 | } 31 | 32 | # Restore old par 33 | par(xaxs = old_xaxs, yaxs = old_yaxs) 34 | 35 | } 36 | -------------------------------------------------------------------------------- /man/miniusa.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/miniusa.R 3 | \name{miniusa} 4 | \alias{miniusa} 5 | \title{Make a tile grid map of The United States of America} 6 | \usage{ 7 | miniusa(states, state_colors, border_colors = rep("white", 51), 8 | state_names = TRUE, state_name_colors = rep("white", 51), 9 | state_name_cex = 1, font = NULL) 10 | } 11 | \arguments{ 12 | \item{states}{A vector of US state postal abbreviations. This vector must be 13 | some permutation of \code{usa_abb}.} 14 | 15 | \item{state_colors}{A vector of "colors" in the R sense. For example strings 16 | (\code{"blue"}), hex codes (\code{"#D0C7B9"}), etc. The ith color in this 17 | vector will be the color of square that represents the ith element of 18 | \code{states}.} 19 | 20 | \item{border_colors}{Like \code{state_colors} but specifying the border 21 | of the square.} 22 | 23 | \item{state_names}{Should the postal codes for each state be displayed in the 24 | center of the state? The default value is \code{TRUE}.} 25 | 26 | \item{state_name_colors}{Like \code{state_colors} but specifying the color 27 | of the text displayed in each state.} 28 | 29 | \item{state_name_cex}{The size of the text displayed inside of each state.} 30 | 31 | \item{font}{The font of the text displayed inside of each state. The values 32 | \code{"serif"}, \code{"sans"}, and \code{"mono"} are safest to use. Use 33 | other fonts at your own risk. If \code{NULL} a sans-style font will be used.} 34 | } 35 | \description{ 36 | Make a tile grid map of The United States of America 37 | } 38 | \examples{ 39 | \dontrun{ 40 | miniusa(state_abb, 1:51) 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /man/minimexico.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/minimexico.R 3 | \name{minimexico} 4 | \alias{minimexico} 5 | \title{Make a tile grid map of Mexico} 6 | \usage{ 7 | minimexico(estados, estados_colors, border_colors = rep("white", 32), 8 | estados_names = TRUE, estados_name_colors = rep("white", 32), 9 | estados_name_cex = 1, font = NULL) 10 | } 11 | \arguments{ 12 | \item{estados}{A vector of Mexican state postal abbreviations. This vector must be 13 | some permutation of \code{mexico_abb}.} 14 | 15 | \item{estados_colors}{A vector of "colors" in the R sense. For example strings 16 | (\code{"blue"}), hex codes (\code{"#D0C7B9"}), etc. The ith color in this 17 | vector will be the color of square that represents the ith element of 18 | \code{estados}.} 19 | 20 | \item{border_colors}{Like \code{estados_colors} but specifying the border 21 | of the square.} 22 | 23 | \item{estados_names}{Should the postal codes for each state be displayed in the 24 | center of the state? The default value is \code{TRUE}.} 25 | 26 | \item{estados_name_colors}{Like \code{estados_colors} but specifying the color 27 | of the text displayed in each state.} 28 | 29 | \item{estados_name_cex}{The size of the text displayed inside of each state.} 30 | 31 | \item{font}{The font of the text displayed inside of each state. The values 32 | \code{"serif"}, \code{"sans"}, and \code{"mono"} are safest to use. Use 33 | other fonts at your own risk. If \code{NULL} a sans-style font will be used.} 34 | } 35 | \description{ 36 | Make a tile grid map of Mexico 37 | } 38 | \examples{ 39 | \dontrun{ 40 | minimexico(mexico_abb, 1:32) 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /man/minicanada.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/minicanada.R 3 | \name{minicanada} 4 | \alias{minicanada} 5 | \title{Make a tile grid map of Canada} 6 | \usage{ 7 | minicanada(pt, pt_colors, border_colors = rep("white", 13), pt_names = TRUE, 8 | pt_name_colors = rep("white", 13), pt_name_cex = 1, font = NULL) 9 | } 10 | \arguments{ 11 | \item{pt}{A vector of Canadian province and territory postal abbreviations. 12 | This vector must be some permutation of \code{canada_abb}.} 13 | 14 | \item{pt_colors}{A vector of "colors" in the R sense. For example strings 15 | (\code{"blue"}), hex codes (\code{"#D0C7B9"}), etc. The ith color in this 16 | vector will be the color of square that represents the ith element of 17 | \code{pt}.} 18 | 19 | \item{border_colors}{Like \code{pt_colors} but specifying the border 20 | of the square.} 21 | 22 | \item{pt_names}{Should the postal codes for each province or territory be 23 | displayed in the center of the province or territory? The default value is 24 | \code{TRUE}.} 25 | 26 | \item{pt_name_colors}{Like \code{pt_colors} but specifying the color 27 | of the text displayed in each province or territory.} 28 | 29 | \item{pt_name_cex}{The size of the text displayed inside of each province or 30 | territory.} 31 | 32 | \item{font}{The font of the text displayed inside of each province or 33 | territory. The values \code{"serif"}, \code{"sans"}, and \code{"mono"} are 34 | safest to use. Use other fonts at your own risk. If \code{NULL} a 35 | sans-style font will be used.} 36 | } 37 | \description{ 38 | Make a tile grid map of Canada 39 | } 40 | \examples{ 41 | \dontrun{ 42 | minicanada(canada_abb, 1:13) 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /R/data.R: -------------------------------------------------------------------------------- 1 | #' Same sex marriage in the US 2 | #' 3 | #' Changes in the legality of same sex marriage in the United States over time. 4 | #' 5 | #' @source \url{http://www.nytimes.com/interactive/2015/03/04/us/gay-marriage-state-by-state.html} 6 | #' @format A data frame with columns: 7 | #' \describe{ 8 | #' \item{State}{State Abbreviation} 9 | #' \item{Status}{Legal status. Either \code{bbs} meaning banned by statute, 10 | #' \code{nl} meaning not legal, \code{legal}, \code{bbca} meaning banned by 11 | #' constitutional ammendment, or \code{dis} meaning disputed.} 12 | #' \item{Year}{Year status went into effect.} 13 | #' } 14 | #' @examples 15 | #' \dontrun{ 16 | #' ssm 17 | #' } 18 | "ssm" 19 | 20 | #' Postal Abbreviations for The United States of America 21 | #' 22 | #' @examples 23 | #' \dontrun{ 24 | #' usa_abb 25 | #' } 26 | "usa_abb" 27 | 28 | #' Postal Abbreviations for Canada 29 | #' 30 | #' @examples 31 | #' \dontrun{ 32 | #' canada_abb 33 | #' } 34 | "canada_abb" 35 | 36 | #' Postal Abbreviations for Mexico 37 | #' 38 | #' @examples 39 | #' \dontrun{ 40 | #' mexico_abb 41 | #' } 42 | "mexico_abb" 43 | 44 | #' Production and farm value of maple products in Canada 45 | #' 46 | #' @source Statistics Canada. Table 001-0008 - Production and farm value of 47 | #' maple products, annual. \url{http://www5.statcan.gc.ca/cansim/} 48 | #' @format A data frame with columns: 49 | #' \describe{ 50 | #' \item{Year}{A value between 1924 and 2015.} 51 | #' \item{Syrup}{Maple products expressed as syrup, total in thousands of gallons.} 52 | #' \item{CAD}{Gross value of maple products in thousands of Canadian dollars.} 53 | #' \item{Region}{Postal code abbreviation for territory or province.} 54 | #' } 55 | #' @examples 56 | #' \dontrun{ 57 | #' maple 58 | #' } 59 | "maple" 60 | 61 | #' Monthly milk production in Canada 62 | #' 63 | #' @source Statistics Canada. Table 003-0011 - Milk production and utilization, 64 | #' monthly. \url{http://www5.statcan.gc.ca/cansim/} 65 | #' @format A data frame with columns: 66 | #' \describe{ 67 | #' \item{Year}{A value between 1976 and 2015.} 68 | #' \item{Month}{A value between 1 and 12.} 69 | #' \item{Region}{Postal code abbreviation for territory or province.} 70 | #' \item{Kiloliters}{Milk sold off farms in kiloliters.} 71 | #' } 72 | #' @examples 73 | #' \dontrun{ 74 | #' milk 75 | #' } 76 | "milk" 77 | -------------------------------------------------------------------------------- /R/minicanada.R: -------------------------------------------------------------------------------- 1 | #' Make a tile grid map of Canada 2 | #' 3 | #' @param pt A vector of Canadian province and territory postal abbreviations. 4 | #' This vector must be some permutation of \code{canada_abb}. 5 | #' @param pt_colors A vector of "colors" in the R sense. For example strings 6 | #' (\code{"blue"}), hex codes (\code{"#D0C7B9"}), etc. The ith color in this 7 | #' vector will be the color of square that represents the ith element of 8 | #' \code{pt}. 9 | #' @param border_colors Like \code{pt_colors} but specifying the border 10 | #' of the square. 11 | #' @param pt_names Should the postal codes for each province or territory be 12 | #' displayed in the center of the province or territory? The default value is 13 | #' \code{TRUE}. 14 | #' @param pt_name_colors Like \code{pt_colors} but specifying the color 15 | #' of the text displayed in each province or territory. 16 | #' @param pt_name_cex The size of the text displayed inside of each province or 17 | #' territory. 18 | #' @param font The font of the text displayed inside of each province or 19 | #' territory. The values \code{"serif"}, \code{"sans"}, and \code{"mono"} are 20 | #' safest to use. Use other fonts at your own risk. If \code{NULL} a 21 | #' sans-style font will be used. 22 | #' 23 | #' @export 24 | #' @examples 25 | #' \dontrun{ 26 | #' minicanada(canada_abb, 1:13) 27 | #' } 28 | minicanada <- function(pt, pt_colors, border_colors = rep("white", 13), 29 | pt_names = TRUE, pt_name_colors = rep("white", 13), 30 | pt_name_cex = 1, font = NULL){ 31 | # Make sure all parameters are specified 32 | if(any(unlist(lapply(list( 33 | pt, pt_colors, border_colors, pt_name_colors 34 | ), length)) != 13)){ 35 | stop("Please make sure parameters contain exactly 13 elements.") 36 | } 37 | 38 | map <- data.frame(State = c("BC", "AB", "SK", "MB", "ON", "QC", "YT", "NT", 39 | "NU", "NB", "NL", "NS", "PE"), 40 | X = c(0:5, 1:3, 6, 6, 7, 7), 41 | Y = c(rep(2, 6), rep(3, 3), 1, 3, 0, 1), 42 | stringsAsFactors = FALSE) 43 | 44 | # Make sure all provinces and territories are present 45 | if(!all(map$State %in% pt)){ 46 | stop("It appears some province or territory names are repeated or missing.") 47 | } 48 | 49 | user_map <- data.frame(State = pt, scol = pt_colors, bcol = 50 | border_colors, sncol = pt_name_colors, 51 | stringsAsFactors = FALSE) 52 | 53 | map <- merge(map, user_map, by = "State") 54 | 55 | text_ <- NULL 56 | if(pt_names){ 57 | text_ <- map$State 58 | } 59 | 60 | plotbox(map$X, map$Y, map$scol, map$bcol, 61 | n_xboxes = 8, n_yboxes = 4, text_ = text_, 62 | text_col = map$sncol, text_cex = pt_name_cex, text_font = font) 63 | 64 | } 65 | -------------------------------------------------------------------------------- /R/minimexico.R: -------------------------------------------------------------------------------- 1 | #' Make a tile grid map of Mexico 2 | #' 3 | #' @param estados A vector of Mexican state postal abbreviations. This vector must be 4 | #' some permutation of \code{mexico_abb}. 5 | #' @param estados_colors A vector of "colors" in the R sense. For example strings 6 | #' (\code{"blue"}), hex codes (\code{"#D0C7B9"}), etc. The ith color in this 7 | #' vector will be the color of square that represents the ith element of 8 | #' \code{estados}. 9 | #' @param border_colors Like \code{estados_colors} but specifying the border 10 | #' of the square. 11 | #' @param estados_names Should the postal codes for each state be displayed in the 12 | #' center of the state? The default value is \code{TRUE}. 13 | #' @param estados_name_colors Like \code{estados_colors} but specifying the color 14 | #' of the text displayed in each state. 15 | #' @param estados_name_cex The size of the text displayed inside of each state. 16 | #' @param font The font of the text displayed inside of each state. The values 17 | #' \code{"serif"}, \code{"sans"}, and \code{"mono"} are safest to use. Use 18 | #' other fonts at your own risk. If \code{NULL} a sans-style font will be used. 19 | #' 20 | #' @export 21 | #' @examples 22 | #' \dontrun{ 23 | #' minimexico(mexico_abb, 1:32) 24 | #' } 25 | minimexico <- function(estados, estados_colors, border_colors = rep("white", 32), 26 | estados_names = TRUE, estados_name_colors = rep("white", 32), 27 | estados_name_cex = 1, font = NULL){ 28 | 29 | # Make sure all parameters are specified 30 | if(any(unlist(lapply(list( 31 | estados, estados_colors, border_colors, estados_name_colors 32 | ), length)) != 32)){ 33 | stop("Please make sure parameters contain exactly 32 elements.") 34 | } 35 | 36 | map <- data.frame(State = c("BCN", "SON", "CHH", "COA", "NLE", 37 | "BCS", "SIN", "DUR", "ZAC", "SLP", "TAM", 38 | "NAY", "AGU", "GUA", "QUE", "HID", 39 | "JAL", "DIF", "TLA", "YUC", 40 | "COL", "MOR", "VER", "TAB", "CAM", "ROO", 41 | "MIC", "MEX", "PUE", "GRO", "OAX", "CHP"), 42 | X = c(c(0, 2:5), 1:6, 2:6, c(3:5, 10), c(4:6, 9:11), 5:10), 43 | Y = c(rep(5, 5), rep(4, 6), rep(3, 5), rep(2, 4), rep(1, 6), 44 | rep(0, 6)), 45 | stringsAsFactors = FALSE) 46 | 47 | # Make sure all states are present 48 | if(!all(map$State %in% estados)){ 49 | stop("It appears some state names are repeated or missing.") 50 | } 51 | 52 | user_map <- data.frame(State = estados, scol = estados_colors, bcol = 53 | border_colors, sncol = estados_name_colors, 54 | stringsAsFactors = FALSE) 55 | 56 | map <- merge(map, user_map, by = "State") 57 | 58 | text_ <- NULL 59 | if(estados_names){ 60 | text_ <- map$State 61 | } 62 | 63 | plotbox(map$X, map$Y, map$scol, map$bcol, 64 | n_xboxes = 12, n_yboxes = 6, text_ = text_, 65 | text_col = map$sncol, text_cex = estados_name_cex, text_font = font) 66 | } 67 | -------------------------------------------------------------------------------- /R/miniusa.R: -------------------------------------------------------------------------------- 1 | #' Make a tile grid map of The United States of America 2 | #' 3 | #' @param states A vector of US state postal abbreviations. This vector must be 4 | #' some permutation of \code{usa_abb}. 5 | #' @param state_colors A vector of "colors" in the R sense. For example strings 6 | #' (\code{"blue"}), hex codes (\code{"#D0C7B9"}), etc. The ith color in this 7 | #' vector will be the color of square that represents the ith element of 8 | #' \code{states}. 9 | #' @param border_colors Like \code{state_colors} but specifying the border 10 | #' of the square. 11 | #' @param state_names Should the postal codes for each state be displayed in the 12 | #' center of the state? The default value is \code{TRUE}. 13 | #' @param state_name_colors Like \code{state_colors} but specifying the color 14 | #' of the text displayed in each state. 15 | #' @param state_name_cex The size of the text displayed inside of each state. 16 | #' @param font The font of the text displayed inside of each state. The values 17 | #' \code{"serif"}, \code{"sans"}, and \code{"mono"} are safest to use. Use 18 | #' other fonts at your own risk. If \code{NULL} a sans-style font will be used. 19 | #' 20 | #' @export 21 | #' @examples 22 | #' \dontrun{ 23 | #' miniusa(state_abb, 1:51) 24 | #' } 25 | miniusa <- function(states, state_colors, border_colors = rep("white", 51), 26 | state_names = TRUE, state_name_colors = rep("white", 51), 27 | state_name_cex = 1, font = NULL){ 28 | 29 | # Make sure all parameters are specified 30 | if(any(unlist(lapply(list( 31 | states, state_colors, border_colors, state_name_colors 32 | ), length)) != 51)){ 33 | stop("Please make sure parameters contain exactly 51 elements.") 34 | } 35 | 36 | map <- data.frame(State = c('ME','AK','VT','NH','MA','WA','MT','ND','SD', 37 | 'MN','WI','MI','NY','CT','RI','OR','ID','WY', 38 | 'NE','IA','IL','IN','OH','PA','NJ','CA','NV', 39 | 'UT','CO','KS','MO','KY','WV','DC','MD','DE', 40 | 'AZ','NM','OK','AR','TN','VA','NC','HI','TX', 41 | 'LA','MS','AL','GA','SC','FL'), 42 | X = c(11,0,9,10,11,1,2,3,4,5,6,7,9,10,11,1,2,3,4,5,6,7,8, 43 | 9,10,0,1,2,3,4,5,6,7,8,9,10,2,3,4,5,6,7,8,0,3,4,5, 44 | 6,7,8,7), 45 | Y = c(7,6,6,6,6,5,5,5,5,5,5,5,5,5,5,4,4,4,4,4,4,4,4,4,4,3 46 | ,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,1,1,1,1,1,1,1,0), 47 | stringsAsFactors = FALSE) 48 | 49 | # Make sure all states are present 50 | if(!all(map$State %in% states)){ 51 | stop("It appears some state names are repeated or missing.") 52 | } 53 | 54 | user_map <- data.frame(State = states, scol = state_colors, bcol = 55 | border_colors, sncol = state_name_colors, 56 | stringsAsFactors = FALSE) 57 | 58 | map <- merge(map, user_map, by = "State") 59 | 60 | text_ <- NULL 61 | if(state_names){ 62 | text_ <- map$State 63 | } 64 | 65 | plotbox(map$X, map$Y, map$scol, map$bcol, 66 | n_xboxes = 12, n_yboxes = 8, text_ = text_, 67 | text_col = map$sncol, text_cex = state_name_cex, text_font = font) 68 | } 69 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/seankross/minimap.svg?branch=master)](https://travis-ci.org/seankross/minimap) 2 | [![codecov.io](https://codecov.io/github/seankross/minimap/coverage.svg?branch=master)](https://codecov.io/github/seankross/minimap?branch=master) 3 | [![CRAN version](http://www.r-pkg.org/badges/version/minimap)](https://cran.r-project.org/web/packages/minimap/index.html) 4 | 5 | # minimap 6 | 7 | A beautiful tile grid map is only a function call away! Tile grid maps are a 8 | great way to display geographic data when you want to represent regions with 9 | equal visual space. No shapefiles required, just supply a vector of postal 10 | abbreviations and a corresponding vector of colors. Built with base graphics. 11 | 12 | If you're unfamilar with tile grid maps, check out the examples below or see the 13 | following news articles: 14 | 15 | - [The New York Times](http://www.nytimes.com/interactive/2015/03/04/us/gay-marriage-state-by-state.html) 16 | - [The Washington Post](https://www.washingtonpost.com/graphics/national/minimum-wage/) 17 | - [National Public Radio](http://blog.apps.npr.org/2015/05/11/hex-tile-maps.html) 18 | 19 | ## Install 20 | 21 | ```r 22 | install.packages("minimap") 23 | ``` 24 | 25 | ## Demos 26 | 27 | ```r 28 | # La Patria Es Primero 29 | 30 | library(minimap) 31 | minimexico(mexico_abb, colorRampPalette(c("#006847", "white", "#CE1126"))(32), 32 | estados_name_colors = rep("black", 32)) 33 | ``` 34 | 35 | ![Mexico](https://raw.githubusercontent.com/seankross/minimap/gh-pages/images/mexico.png) 36 | 37 | ```r 38 | # Legal Status of Same Sex Marriage in the United States (2008) 39 | 40 | library(minimap) 41 | 42 | determine_color <- function(status){ 43 | if(status == "bbs") 44 | "#FFE597" 45 | else if(status == "nl") 46 | "#F1F1F0" 47 | else if (status == "dis") 48 | "#D0C7B9" 49 | else if(status == "bbca") 50 | "#FDC471" 51 | else 52 | "#817972" 53 | } 54 | 55 | ssm$color <- as.character(sapply(ssm$Status, determine_color)) 56 | ssm_2008 <- ssm[ssm$Year == 2008,] 57 | miniusa(ssm_2008$State, state_colors = ssm_2008$color, state_names = TRUE, 58 | state_name_colors = rep("white", 51)) 59 | title(main = "Legal Status of Same Sex Marriage in 2008", line = -1) 60 | ``` 61 | 62 | ![USA](https://raw.githubusercontent.com/seankross/minimap/gh-pages/images/usa.png) 63 | 64 | ```r 65 | # Legal Status of Gay Marriage Over Time 66 | 67 | library(minimap) 68 | 69 | old_mai <- par()$mai 70 | par(mai = c(0, 0, .75, .5), mfrow = c(2, 4)) 71 | 72 | for(i in 2008:2015){ 73 | one_year <- ssm[ssm$Year == i,] 74 | miniusa(one_year$State, state_colors = one_year$color, state_names = FALSE) 75 | title(main = i, line = -2) 76 | } 77 | 78 | mtext("Legal Status of Gay Marriage Over Time", outer = TRUE, side = 3, line = -2) 79 | 80 | par(mai = old_mai, mfrow = c(1, 1)) 81 | ``` 82 | 83 | ![USA](https://raw.githubusercontent.com/seankross/minimap/gh-pages/images/usam.png) 84 | 85 | ```r 86 | # Forty Years of Canadian Milk Production 87 | 88 | library(minimap) 89 | library(dplyr) 90 | library(RColorBrewer) 91 | library(animation) 92 | 93 | bin <- function(x){ 94 | qs <- as.numeric(quantile(x, seq(0, 1, .1))) 95 | sapply(x, function(y){ 96 | which(abs(qs-y)==min(abs(qs-y))) 97 | }) 98 | } 99 | 100 | milk_year <- milk %>% 101 | group_by(Region, Year) %>% 102 | summarise(Total_kL = sum(Kiloliters)) 103 | 104 | max_milk <- milk_year %>% 105 | group_by(Region) %>% 106 | summarise(Max = max(Total_kL)) 107 | 108 | milk_year <- milk_year %>% 109 | left_join(max_milk) %>% 110 | group_by(Region) %>% 111 | mutate(Bin = bin(Total_kL)) %>% 112 | select(Region, Year, Bin) 113 | 114 | missing_pt <- setdiff(canada_abb, unique(milk_year$Region)) 115 | 116 | missing_milk <- data.frame(Region = rep(missing_pt, each = 40), 117 | Year = rep(1976:2015, 3), 118 | Bin = rep(0, 120), stringsAsFactors = FALSE) 119 | milk_year <- rbind(milk_year, missing_milk) 120 | 121 | milk_year$color <- sapply(milk_year$Bin, function(x){ 122 | if(x == 0){ 123 | "grey80" 124 | } else { 125 | brewer.pal(11, "PuOr")[x] 126 | } 127 | }) 128 | 129 | ani.options(interval = 0.4, ani.width = 600, ani.height = 450) 130 | 131 | saveGIF( 132 | for(i in 1976:2015){ 133 | milkgif <- milk_year[milk_year$Year == i,] 134 | minicanada(milkgif$Region, pt_colors = milkgif$color, pt_name_cex = 1.5) 135 | title(main = paste("Canadian Milk Production in", i), line = -1) 136 | } 137 | ) 138 | ``` 139 | 140 | ![Canada](https://raw.githubusercontent.com/seankross/minimap/gh-pages/images/canada.gif) 141 | 142 | 143 | ```r 144 | # Legal Status of Gay Marriage Over Time (gif) 145 | 146 | library(minimap) 147 | library(animation) 148 | 149 | determine_color <- function(status){ 150 | if(status == "bbs") 151 | "#FFE597" 152 | else if(status == "nl") 153 | "#F1F1F0" 154 | else if (status == "dis") 155 | "#D0C7B9" 156 | else if(status == "bbca") 157 | "#FDC471" 158 | else 159 | "#817972" 160 | } 161 | 162 | ssm$color <- as.character(sapply(ssm$Status, determine_color)) 163 | 164 | ani.options(interval = 0.5, ani.width = 600, ani.height = 450) 165 | 166 | saveGIF( 167 | for(i in 1992:2015){ 168 | one_year <- ssm[ssm$Year == i,] 169 | miniusa(one_year$State, state_colors = one_year$color) 170 | title(main = paste("Legal Status of Same Sex Marriage in", i), line = -1) 171 | } 172 | ) 173 | ``` 174 | 175 | ![USA](https://raw.githubusercontent.com/seankross/minimap/gh-pages/images/usa.gif) --------------------------------------------------------------------------------