micromapST {micromapST} | R Documentation |
Linked Micromap Graphics Package
Description
Provides a easy and quick means of creating Linked Micromaps for any collection of geographically associated areas. The micromapST package uses the standard graphics and RColorBrewer packages to rapidly create highly readable linked micromap plots. This gives the user the ability to explore different views of their data quickly.
micromapST uses the border and name information contained in border group datasets to define the geographical areas used in creating the linked micromaps.
The micromapSEER function is included to help users of the specialized micromapST for NCI Seer areas called micromapSEER migrate to this package. The micromapSEER function, calls micromapST with the border group set to USSeerBG to generate linked micromaps for the 20 U. S. Seer Areas.
The micromapST contains border group datasets with the boundary and name information for the following::
-
USStatesBG - data from the original micromapST package for . the U. S. 50 states and the District of Columbia.
-
USSeerBG - data for the 21 U. S. Seer Areas.
-
KansasBG - data for the 105 counties in the state of Kansas.
-
NewYorkBG - data for the 62 counties in the state of New York.
-
MarylandBG - data for the 24 counties in the state of Maryland.
-
UtahBG = data for the 29 counties in the state of Utah
-
ChinaBG - 34 administrative areas in the country of China.
-
UKIrelandBG - 218 administrative areas in UK, Ireland and Isle of Man.
-
SeoulKoreaBG - 25 districts in Seoul S. Korea.
-
AfricaBG - 52 countries of the Africa continent.
Each plot row represents a single sub-area (state, county or province) within
the border group area. Each column can be defined to present a different
graphical representations of the user's data.
For linked micromaps, the primary columns are a MAP type, ID (sub-area name)
and one or more glyphics. The statistical data is presented in the
glyphics columns as one of the following glyph types:
arrows,
bars,
boxplots,
dots,
dots with confidence intervals,
dots with standard error,
dot with a significance marker,
time series line plots with or without confidence bands,
scatter plots, and
horizontal stacked (segmented, centered, and normalized) bars.
All border groups are distrbuted with the package as .rda datasets.
Usage
micromapST ( statsDFrame,
panelDesc,
rowNamesCol = NULL,
rowNames = NULL,
sortVar = NULL,
ascend = TRUE,
title = c("", ""),
plotNames = NULL,
axisScale = NULL,
staggerLab = NULL,
bordGrp = NULL,
bordDir = NULL,
dataRegionsOnly = NULL,
regionsB = NULL,
grpPattern = NULL,
maxAreasPerGrp = NULL,
ignoreNoMatches = FALSE,
colors = NULL,
details = NULL)
Arguments
statsDFrame |
a data.frame containing data used with the following plots/glyphs:.
arrow, bar, segbar, normbar, ctrbar,
dot, dotse, dotconf, dotsignif,
and scatdot plots.
The data for the boxplot and time series plots (TS and TSConf)
is more complex and multi-dimensional and is passed to the glyph generation routines
via the panelData parameter (see below for more details.) |
panelDesc |
a data.frame that defines the description of each column: types, associated data columns in the stateFrame data.frame, column titles (top and bottom), reference values and text, and names of additional data.frames for complex glyphics (time series and boxplots). See section on panelDesc data.frame. for more details. |
rowNames |
defines the type of value used as the row.names in the stateFrame. The options are:
See the documentation on each border group for details on
the full names, abbreviatations, optional alternate abbreviations
and numeric identifiers defined for each area in the particular
border group in the areaNamesAbbrsIDs R object. If a border group does not have one of these sets of name data, then the corresponding option will not be available. The linkage between data and boundaries is accomplished using the strings in the
statsDFrame column identified by rowNamesCol or if no rowNamesCol is specified in
the The linkage values are validated to against the areaNamesAbbrsIDs data.frame for the specified border group for the micromapST call. If a sub-area in the border group is not referenced in the data, it is outlined on the map, but not colored. If the sub-area link cannot be matched, a warning message is generated and the execution of the package is stopped. Unless, the user has set the noMatchIgnore call argument to TRUE and the data will be ignored. The alias option is implemented to support with the USSeerBG border group and data generated by the Seer Stat program. The registry column identifying the Seer Area contains the Seer Area name and additional information. This option along with the alias field in the border group allows the package to use the registry column as the linkage to the boundary data using a wildcard or partial string allows the registry column generated by Seer Stat to be used as the linkage. This option is controlled the enableAlias variable in the border group's areaParms data.frame. |
rowNamesCol |
allows the user to specify the data.frame column that contains the sub-area string to be used to link the data row to the boundary data for the sub-area. The rowNames option above specifies which name information (full name, abbreviation, id, alternate abbreviations) the sub-area string is matched to in the border group name information. (see the border group documentation for more details.) The rowNamesCol value must be a column number or column name within the statsDFrame data.frame. The default value for rowNamesCol is to use row.names of the passed data.frame. |
sortVar |
defines the column name(s) or number(s) in the statsDFrame data.frame to be used to sort the statsDFrame data.frames before creating the state micromap. A vector of column names or numbers can be used sort on multiple columns and to break ties. For Example: |
ascend |
a logical value. If TRUE, sortVar will be sorted in ascending order. If FALSE, sortVar will be sorted in descending order. The default value is TRUE. |
title |
A character vector with one or two character strings to be used as the title of the overall micromap plot page. For example: \code{title = "micromapST Title"} or \code{title = c("title line 1","title line 2")} |
plotNames |
defines the type of state names to be displayed when an id glyph column
requested. The options are: ab or full.
ab will display the area abbreviations in uppercase as defined in the border
groups name information. |
axisScale |
defines the type of axis labels to be used and if scaling is applied. The acceptable values are o, w, s, and sn. o is the original method using the pretty function limiting the values to the range of the data. w is the default and uses the Wilkinson algorithm to generate the axis labels for a set of data, s uses the wilkinson algorithm, adjusts the range to cover the labels, and determines a scaling to apply to the labels. If 1000 is the scaling, "in the thousands" is added to the column titles. sn uses the wilkinson algorithm, adjusts the range to cover the labels, and checks each value to determine if it should be scaled. If it is scales, the scale identifier is added as a suffix. (e.g., 1240334 become 1.24M) "w" is the wilkinson algorithm without any scaling. |
staggerLab |
is a logical variable the controls if the axis labels are staggered and drawn on on two lines instead of one. If set to FALSE (the default), the labels are not staggered. If TRUE, two lines are used to draw the axis labels, alternating labels on each line. |
bordDir |
specifies the path to a border group dataset (.rda) that is external to the micromapST package. The name of the border group is specified in the bordGrp parameter. |
bordGrp |
specifies which preloaded border group to use for the area names, abbreviations, numeric identifier, and area boundary data. The supported border groups are USStatesBG and USSeerBG. The default bordGrp value is USStatesBG. For more information on building your own border group refer to the section in this manual on the BuildBorderGroup function. |
dataRegionsOnly |
specifies to only map regions containing data when aP_Regions is set to TRUE. This indicates the name table contains the information to draw partial area maps of regions. When set to TRUE, only regions within the area are drawn that contain at least one sub-area with data provided by the caller. If FALSE, the entire area is drawn. The default is FALSE. Retional boundaries are not required, but suggested. See border group documentation for more details. |
regionsB |
when regional boundaries are provided, controls whether to overlay the boundaries on the map. If dataRegionsOnly is set to TRUE and only a subset of regions will be mapped and regional boundaries are provided, regionsB is et to TRUE. The default is FALSE. Independent of dataRegionsOnly, if set to TRUE, if present, regional boundaries are overlayed on the map, If set to FALSE, no regional boundaries are drawn. See border group documentation for more details. |
grpPattern |
The micromapST package generates the pattern of rows to panel groups automatically. The pattern is based on a maximum of 5 rows per group and number of rows can only decend from the edges toward the median row. The pattern generated by the package can be overriden by using the grpPattern to specify the pattern to use as a numeric vector. The provided vector must pass the following checks: a) must be a numeric vector, b) the sum of the values in the vector must equal the number of rows in the user supplied statsDFrame data frame c) the maximum number of rows per panel group is 5. d) the number of rows per panel must be integers and decending from the outside to the middle of the vector. |
maxAreasPerGrp |
This parameter defines the maximum number of areas to be represented by a group-row in the resulting linked micromap. The value can be 5 or 6. |
ignoreNoMatches |
The micromapST package will automatically handle situations where there is no data for a sub-area in an area. However, it will stop processing if there is data for a non-existing area. To instruct the package to ignore rows of data for sub-areas that do not have boundary information in the border group, set the call argument ignoreNoMatches to TRUE to get the package to detail the data rows from the processing. |
colors |
is a vector containing a vector of 12 or 24 color names or values ("#xxxxxx") or the name of a color palette. The vector of 12 or 24 color names or "#xxxxxx" values are used to define the colors used for:
The only color palette support is a gray palette to permit publication of the linked micromaps using a gray scale instead of color. By setting colors = "greys", "grays", or "bw", the entire plot will be generated using gray scale that has been balanced to maintain readability and reproduction without the use of color printing. Additional color palettes may be supported in future releases. If a colors vector is not provided, the package default colors will be used:
It is strongly recommended to use the default. |
details |
defines the spacing, line widths and many other details of the plot layout, structure and content; see micromapGDefaults$details for more details. Generally details does not need to be specified, the default values will always be used and are strongly recommended. However, in a few cases, it may be desireable to turn off or disable a feature. In these cases, the user can specify just the specific variable and value in a list and pass it to micromapST via the details parameter. For example: details=list(SNBar.Middle.Dot=FALSE,SBar.varht=FALSE) The entire details variable list does not have to be passed. See the section on the micromapGDefaults$details for more details. |
Details
The micromapST function creates a linked micromap plot for data referencing a collection of geographic related areas, like the 50 US States and DC geographical areas or U.S. Seer Areas. The function provides links from a US state map to several forms of graphical charts: dot (dot), dot with confidence intervals (dotconf), dot standard error (dotse), dot with significance mark (dotsignif), arrow (arrow), bar chart (bar), time series (ts), time series with a confidence band (tsconf), horizontal stacked (segmented) bar (segbar), normalized bar (normbar), centered bar charts (ctrbar), scattered dot (scatdot), and box plots (boxplot). The data values for each column of graphs and each area are provided in the statsDFrame data.frame. The panelDesc data.frame specifies the type of chart, the column numbers in the statsDFrame with the statistics for the chart, column titles, reference values, etc. Additional data for boxplots and time series plots are provided through the panelData data.frame column.
The following sets of data have been included in the package to support the examples and provide samples of data the micromapST package can utilize.
Dataset contained in the package to support the examples provides are:
- statePop2010
U. S. State population data for 2010.
- TSdata
To be Added
- Educ8thData
To be Added
- stateData
To be Added
- wflung00and95
White Female Lung (wflung) data from 1995 and 2000
- wflung00cnty
Wflung US data for 2000 by county.
- wflung00and95US
Wflung US data for 2000 and 1995.
- wflung5070
Wflung data for 50s to 70s
- wflung5070US
Wflung data for 50s to 70s US rates
- KanPopInc
Kansas state population by county.
- mdPopData
Maryland state population by county.
- nyPopData
New York state population by county.
- UtahPopData
Utah state population by county.
- AfricaPopData
Africa population by country.
- SeoulPopData
Seoul City population by district.
- cnPopData
China population by province and adminstrative district.
Value
None
Author(s)
Daniel B. Carr, George Mason University, Fairfax VA, with contributions from Jim Pearson and Linda Pickle of StatNet Consulting, LLC, Gaithersburg, MD
References
Daniel B. Carr and Linda Williams Pickle, Visualizing Data Patterns with Micromaps, CRC
Press, 2010
Linda Williams Pickle, James B. Pearson Jr., Daniel B. Carr (2015), micromapST: Exploring and Communicating Geospatial Patterns in US State Data.,
Journal of Statistical Software, 63(3), 1-25., https://www.jstatsoft.org/v63/i03/
See Also
Examples
###
#
# micromapST - Example # 01 - map with no cumulative shading,
# 2 columns of statistics: dot with 95% confidence interval,
# boxplot sorted in descending order by state rates, using
# the default border group of "USStatesBG", with default symbols.
###
# load sample data, compute boxplot
TDir<-"c:/projects/statnet/" # my private test PDF directory exist, don't use temp.
if (!dir.exists(TDir)) {TDir <- paste0(tempdir(),"/") } # get a temp directory for the output
# PDF files for the example.
cat("TempDir:",TDir,"\n")
# replace this directory name with the location if you want to same
# the output from the examples.
utils::data(wflung00and95,wflung00and95US,wflung00cnty,envir=environment())
wfboxlist = graphics::boxplot(split(wflung00cnty$rate,wflung00cnty$stabr),
plot=FALSE)
# set up 4 column page layout
panelDesc01 <- data.frame(
type=c("map","id","dotconf","boxplot"),
lab1=c("","","State Rate","County Rates"),
lab2=c("","","and 95% CI","(suppressed if 1-9 deaths)"),
lab3=c("","","Deaths per 100,000","Deaths per 100,000"),
col1=c(NA,NA,1,NA),col2=c(NA,NA,3,NA),col3=c(NA,NA,4,NA),
refVals=c(NA,NA,NA,wflung00and95US[1,1]),
refTexts=c(NA,NA,NA,"US Rate 2000-4"),
panelData= c("","","","wfboxlist")
)
panelDesc <- panelDesc01
# set up PDF output file, call package
ExTitle <- c("Ex01-US White Female Lung Cancer Mortality, 2000-2004",
"State Rates & County Boxplots")
grDevices::pdf(file=paste0(TDir,"Ex01-US-WFLung-2000-2004-St-DotCf-Co-Box.pdf"),
width=7.5,height=10)
micromapST(wflung00and95, panelDesc01, sortVar=1, ascend=FALSE,
title=ExTitle
)
x <- grDevices::dev.off()
#
### End Example 01
###
#
# micromapST - Example # 02 - map with cumulative shading
# from top down (mapcum), arrow and bar charts,
# sorted in descending order by starting
# value of arrows (1950-69 rates) using default
# border group of "USStatesDF". This
# example also provides custom colors for the
# linked micromaps, highlights, etc.
#
###
# Load example data from package.
utils::data(wmlung5070,wmlung5070US,envir=environment())
panelDesc02 <- data.frame(
type=c("mapcum","id","arrow","bar"),
lab1=c("","","Rates in","Percent Change"),
lab2=c("","","1950-69 and 1970-94","1950-69 To 1970-94"),
lab3=c("MAPCUM","","Deaths per 100,000","Percent"),
col1=c(NA,NA,"RATEWM_50","PERCENT"),
col2=c(NA,NA,"RATEWM_70",NA)
)
colorsRgb = matrix(c( # the basic 7 colors.
213, 62, 79, #region 1: red #D53E4F - Rust Red
252, 141, 89, #region 2: orange #FC8D59 - Brn/Org
253, 225, 139, #region 3: green #FEE08B - Pale Brn
153, 213, 148, #region 4: greenish blue #99D594 - med Green
50, 136, 189, #region 5: lavendar #3288BD - Blue
255, 0, 255, #region 6 #FF00FF - Magenta
.00, .00, .00, #region 7: black for median #000000 - Black
230, 245, 152, #non-highlighted foreground #E6F598 - YellowGreen
255, 174, 185, # alternate shape upper #FFAEB9 - Mauve
191, 239, 255, # alternate shape lower #BFEFFF - Cyan
242, 242, 242, # lightest grey for non-referenced sub-areas #F2F2F2
234, 234, 234), # lighter grey for bkg - non-active sub-areas. #EAEAEA
ncol=3,byrow=TRUE)
xcolors = c( grDevices::rgb(colorsRgb[,1],colorsRgb[,2],colorsRgb[,3],
maxColorValue=255),
# set solid colors
grDevices::rgb(colorsRgb[,1],colorsRgb[,2],colorsRgb[,3],64,
maxColorValue=255))
# set translucent colors for time series.
# set up reference names for color set
names(xcolors) =c("rustred","orange","lightbrown","mediumgreen",
"blue","magenta", "black","yellowgreen",
"mauve","cyan","lightest grey","lighter grey",
"l_rustred","l_orange","vlightbrown","lightgreen",
"lightblue","l_black","l_yelgreen","l_mauve",
"l_cyan","l_lightest grey","l_lighter grey")
ExTitle <- c("Ex02-US Change in White Male Lung Cancer Mortality Rates",
"from 1950-69 to 1970-94-Diff colors")
grDevices::pdf(file=paste0(TDir,"Ex02-US WmLung50-70-Arrow-Bar.pdf"),width=7.5,height=10)
micromapST(wmlung5070,panelDesc02,sortVar=1,ascend=FALSE,
title=ExTitle, colors=xcolors
)
x <- grDevices::dev.off()
#
### End Example 02
## Not run:
###
#
# micromapST - Example # 03 - Time Series Line Plots with
# Confidence Bands maptail option highlights states from extremes
# to middle state read in time series data set example using the
# default border group of "USStatesDF".
#
###
# Load example data from package.
utils::data(TSdata,envir=environment())
temprates <- data.frame(TSdata[,,2])
# TSdata structure is array of size c(51,15,4),
# dimensions = 51 states, 15 years, (year label, point value, low limit,
# high limit)
panelDesc03 <- data.frame(
type=c("maptail","id","tsconf","dot"),
lab1=c("","","Time Series","Female"),
lab2=c("","","Annual Rate per 100,000","Most Recent Rate (2010)"),
lab3=c("","","Years","Deaths per 100,000"),
lab4=c("","","Rate",""),
col1=c(NA,NA,NA,15),
panelData =c(NA,NA,"TSdata",NA)
)
ExTitle <- c("Ex03-US Time Series with Confidence bands",
"Annual Female Lung Cancer Mortality Rates, 1996-2010")
grDevices::pdf(file=paste0(TDir,"Ex03-US Time-Series-with-Conf.pdf"),
width=7.5,height=10)
micromapST(temprates,panelDesc03,sortVar="P15",ascend=FALSE,
title=ExTitle)
x <- grDevices::dev.off()
#
### End Example 03
## End(Not run)
###
#
# micromapST - Example # 03a - Time Series Line Plots with
# Confidence Bands maptail option highlights states from extremes
# to middle state read in time series data set example using the
# default border group of "USStatesDF".
#
# Specify the x-Axis values are dates and to format them as dates.
###
# Load example data from package.
utils::data(TSdata,envir=environment())
temprates <- data.frame(TSdata[,,2]) # y rate
# In the original package TS data, the x data was not
# a date value, it was the year number. To be able to demonstrate
# the X-Axis Date format labeling, these were changed to Date values
# by effectively substracting 1970-1-1 from the year value.
####
#
# Example 3a - Building TS conf array and converting years
# into date values for the X-Axis and labels.
#
# example of build a TS Conf array.
#
# Using the old TSdata array as a starting point and source of data,
# but build an entirely new TS array structure in a similar manner
# that might be used to build your own time series array.
#
data(TSdata) # get old array
TSAreas <- row.names(TSdata) # one per area (index 1)
NewArray <- array(dim=c(51,15,4),dimnames=list(TSAreas))
# this is for 51 states, 15 samples/observations, and 4 values per sample.
for (inx in seq(1,length(TSAreas))) { # loop once per area
Samp <- TSdata[inx,,] # samples for an area
# each sample has 15 observations of 4 values.
# value 1 is the X axis data or the DATE of the observation
Samp[,1] <- as.Date(paste0(as.character(Samp[,1]),"-01-01"))
# convert simple year number to date
NewArray[inx,,] <- Samp
}
# setting the attribute "xIsDate" on array to TRUE, signals micromapST
# the user wants to see the x-axis values as dates.
## Not run:
attr(NewArray,"xIsDate") <- TRUE
# TSdata and NewArray structures are arrays of size c(51,15,4),
# dimensions = 51 states, 15 years, (year label, point value, low limit, high limit)
panelDesc03a <- data.frame(
type=c("maptail","id","tsconf","dot"),
lab1=c("","","Time Series (YYYY-MM)","Female"),
# recommend adding to the column title a note about the date format used.
lab2=c("","","Annual Rate per 100,000","Most Recent Rate (2010)"),
lab3=c("","","Years","Deaths per 100,000"),
lab4=c("","","Rate",""),
col1=c(NA,NA,NA,15),
panelData =c(NA,NA,"NewArray",NA)
)
ExTitle <- c("Ex03a-US Time Series with Confidence bands with time (yyyy-mm)",
"Annual Female Lung Cancer Mortality Rates, 1996-2010")
grDevices::pdf(file=paste0(TDir,"Ex03a-US Time-Series-with-Conf wDates.pdf"),
width=7.5,height=10)
micromapST(temprates,panelDesc03a,sortVar="P15",ascend=FALSE,
axisScale="s",
title=ExTitle)
x <- grDevices::dev.off()
## End(Not run)
#
### End Example 03a
###
#
# micromapST - Example 04 - dot followed by a scatter dot columns
# use same data as Example 3 to compare 1996 & 2010 rates
# mapmedian option shades states above or below the median
# (light yellow) using the default border group of "USStatesBG"
#
# USES data loaded for Example 03 (temprates).
#
####
# Load example data from package.
utils::data(TSdata,envir=environment())
temprates <- data.frame(TSdata[,,2]) # y rate
panelDesc04 <- data.frame(
type=c("mapmedian","id","dot","scatdot"),
lab1=c("","","Female Lung Cancer Mortality","Comparison of Rates"),
lab2=c("","","Rate in 1996 (Sort Variable)",
"in 1996 (x axis) and 2010 (y axis)"),
lab3=c("","","Deaths per 100,000","Deaths per 100,000 in 1996"),
lab4=c("","","","Rate in 2010"),
col1=c(NA,NA,1,1),
col2=c(NA,NA,NA,15)
)
ExTitle <- c("Ex04-US Dot Plot for 1996, Scatter Plot Comparing 1996 to 2010",
"Female Lung Cancer Mortality Rates")
FName <- paste0(TDir,"Ex04-US FLCMR Scatter-Dots-1996-2010.pdf")
grDevices::pdf(file=FName,width=7.5,height=10)
micromapST(temprates,panelDesc04,sortVar=1,ascend=FALSE,title=ExTitle)
x <- grDevices::dev.off()
#
### End Example 04
###
#
# micromapST - Example 05 - horizontal stacked (segmented) bars
# segbar plots the input data, normbar plots percent of total
# package computes the percents from input data
# input for the categories for each state must be in consecutive
# columns of the input data.frame using the default border group
# of "USStatesBG"
####
# Load example data from package.
utils::data(statePop2010,envir=environment())
panelDesc05 <- data.frame(
type=c("map","id","segbar","normbar"),
lab1=c("","","Stacked Bar","Normalized Stacked Bar"),
lab2=c("","","Counts","Percent"),
col1=c(NA,NA,"Hisp","Hisp"),
col2=c(NA,NA,"OtherWBH","OtherWBH")
)
ExTitle <- c("Ex05-Stkd Norm Bars: 2010 Census Pop by Race, Sorted by Cnt Other Race",
"Cat-L to R: Hispanic, non-Hisp White, Black, Other-sn-varbar")
grDevices::pdf(file=paste0(TDir,"Ex05-US Stkd-Norm Bar-var-height.pdf"),
width=7.5,height=10)
micromapST(statePop2010, panelDesc05, sortVar="OtherWBH", ascend=FALSE,
title= ExTitle,
details=list(SNBar.varht=TRUE), axisScale="sn" )
x <- grDevices::dev.off()
#
### End Example 05
## Not run:
###
#
# micromapST - Example 06 - horizontal stacked (segmented) bars
# segbar plots the input data, normbar plots percent of total
# package computes the percents from input data
# input for the categories for each state must be in consecutive
# columns of the input data.frame using the default border group
# of "USStatesBG".
#
# Turning off the variable bar height and the midpoint dot features
# in the horizontal stacked bars (segmented)
#
# USES data loaded for Example 05 above - statePop2010.
#
###
# Reuse data loaded for Example 5 above.
panelDesc06= data.frame(
type=c("map","id","segbar","normbar"),
lab1=c("","","Stacked Bar","Normalized Stacked Bar"),
lab2=c("","","Counts","Percent"),
col1=c(NA,NA,"Hisp","Hisp"),
col2=c(NA,NA,"OtherWBH","OtherWBH")
)
ExTitle <- c("Ex06-Stacked Norm Bars: 2010 Census Pop by Race, Sorted by Other Race",
"Cat-L to R: Hisp, non-Hisp White, Black, Other,ID-diamond")
grDevices::pdf(file=paste0(TDir,"Ex06-Stkd-Norm-Bar-fixedheight-nodot.pdf"),
width=7.5,height=10)
micromapST(statePop2010,panelDesc06,sortVar=4,ascend=FALSE,
title= ExTitle,
details=list(SNBar.Middle.Dot=FALSE,SNBar.varht=FALSE,Id.Dot.pch=23)
)
x <- grDevices::dev.off()
#
### End Example 06
## End(Not run)
###
#
# micromapST - Example 07 - centered (diverging) stacked bars
#
# National 8th grade Math Proficiency NAEP Test Scores Data for 2011
# source: National Center for Education Statistics,
# http://nces.ed.gov/nationsreportcard/naepdata/
# bar segment values - % in each of 4 categories:
# % < Basic, % at Basic, % Proficient, % Advanced
# using the default border group of "USStatesBG".
####
# Load example data from package.
utils::data(Educ8thData,envir=environment())
# columns = State abbrev, State name, Avg Score, %s \<basic,
# basic, proficient, advanced
panelDesc07 <- data.frame(
type=c("map","id","dot","ctrbar"),
lab1=c("","","Avg. Scores","Math Proficiency"),
lab2=c("","","","<Basic, Basic, Proficient, Advanced"),
lab3=c("","","","% to Left of 0 | % to Right"),
col1=c(NA,NA,"avgscore","PctBelowBasic"),
col2=c(NA,NA,NA,"PctAdvanced")
)
ExTitle <- c("Ex07-US Dot Stkd Bars:Educational Progress (NAEP) in Math-2011, 8th Grade",
"Centered at Not-Prof vs. Prof")
grDevices::pdf(file=paste0(TDir,"Ex07-US Dot-Centered-Bar Educ.pdf"),width=7.5,height=10)
micromapST(Educ8thData,panelDesc07,
sortVar=3,
title=ExTitle)
x <- grDevices::dev.off()
#
### End of example 07
## Not run:
###
#
# Example 08 - use of state.x77 data table as data source
# Data does not contain a row for DC, a missing sub-area.
# Example also uses a smaller then 7.5 x 10 graphic space.
#
###
utils::data(state,envir=environment())
stateData <- as.data.frame(state.x77)
rownames(stateData) <- state.abb
panelDesc08 <- data.frame(type = c("maptail", "id", "dot"),
lab1 = c("", "", "Murder"),
lab3 = c("", "", "Murders per 100K Population"),
col1 = c(NA, NA, 5))
ExTitle <- c("Ex08-US LM Plot of Murders in the United States",
"No DC row entry.")
grDevices::pdf(file = paste0(TDir,"Ex08_US state.x77_no_DC.pdf"),
width = 5, height = 9)
micromapST(stateData, panelDesc08,
sortVar = 5, ascend = FALSE,
title = ExTitle)
x <- grDevices::dev.off()
#
### End Example 08
## End(Not run)
###
#
# Example 09 - US state map based on data from state.x77 table with
# DC row added to complete data.frame, but with missing values (NAs).
# The DC row will be sorted to the bottom of the list size
# it does not contain any data.
#
# Used data and the panelDesc data.frames (stateData and panelDesc16)
# used in example 09.
#
###
panelDesc09 <- data.frame(type = c("maptail", "id", "dot"),
lab1 = c("", "", "Murder"),
lab3 = c("", "", "Murders per 100K Population"),
col1 = c(NA, NA, 5))
# add DC as 51st state with missing data "NA" to stateData.
rm(state)
utils::data(state,envir=environment())
stateData <- as.data.frame(state.x77)
rownames(stateData) <- state.abb
stateData <- rbind(stateData, DC = rep(NA, 8))
# missing values for DC row.
ExTitle <- c("Ex09-US-LM Plot of Murders in the United States",
"DC row added with NA, decending.")
grDevices::pdf(file =paste0(TDir,"Ex09_US_state.x77_DCasNA_D.pdf"),
width = 5, height = 9)
micromapST(stateData, panelDesc09,
sortVar = 5, ascend = FALSE,
title = ExTitle)
x <- grDevices::dev.off()
#
### End Example 09
###
#
# Example # 10 - Maps Seer Registries using the micromapST function
# with the bordGrp = "USSeerBG".
#
###
# Load example data from package.
utils::data(Seer18Area,envir=environment())
# set up 4 column page layout
panelDesc10 = data.frame(
type=c("mapcum","id","dotsignif","arrow")
,lab1=c("","","Rate Trend APC", "Rate Change")
,lab2=c("","","Dot-Signif","2002-06 to 2007-11")
,lab3=c("","","","")
,col1=c(NA,NA,"RateTrendAPC","Rate20022006")
,col2=c(NA,NA,"pValue", "Rate20072011")
)
ExTitle <- c("Ex10-SeerStat Data-2002-6 and 2007-11",
"Dot with Signif., Arrow and Bar")
grDevices::pdf(file=paste0(TDir,"Ex10-SeerStat-DotSignif.pdf"),width=7.5,height=10)
micromapST(Seer18Area,panelDesc10,
sortVar="Rate20022006",ascend=FALSE,
title=ExTitle,
rowNames="alias",rowNamesCol='Registry',
bordGrp="USSeerBG",
plotNames="ab")
x <- grDevices::dev.off()
#
# Both calls are effectively identical.
#
### End of example 10
###
#
# Example # 11 - Counties in Kansas on an 11 x 17 page
#
###
# Load example data from package.
utils::data(KansPopInc,envir=environment())
# Four Column Layout: Map, ID, Dot, and Dot
panelDesc11 = data.frame(
type=c("map","id","dot", "dot")
,lab1=c("", "", "Population", "Average Inc.")
,lab2=c("", "", "in 2000", "per year")
,lab3=c("", "", "People", "")
,col1=c(NA, NA, "Pop", "AvgInc")
)
ExTitle <- c("Ex11-Kansas Pop data 11x17",
"Current Pop and Average Inc - scaling=e")
grDevices::pdf(file=paste0(TDir,"Ex11-Kansas_Population_and_Income-11x17.pdf"),
width=10, height=16)
# tabloid size page (11x17) to handle 105 counties.
# Use default scaling = "e" and no staggered labels,
# Use full county names for data to boundary matching,
# but presented abbreviated county names
# in "id" glyphic column with large page.
micromapST(KansPopInc, panelDesc11,
sortVar=c("AvgInc","Pop"), ascend=FALSE,
title=ExTitle,
rowNames="full", rowNamesCol='County',
bordGrp="KansasBG",
plotNames="ab")
x <- grDevices::dev.off()
#
### End Example 11
###
#
# micromapST - Example 12 - A linked micromap of the counties of
# the state of Maryland using the border group "MarylandBG".
# The MarylandPopInc data is shown using two dot glypics - current
# population and average increase per county.
# A "maptail" state map is used to show the counties in relationship
# to the median county as sorted by the 1970 population.
###
utils::data(mdPopData,envir=environment())
# set up 5 column page layout
panelDesc12 = data.frame(
type=c("maptail","id","dot","dot","arrow")
,lab1=c("","","Population", "Population","Change")
,lab2=c("","","in 1970","in 2000", "from 1970 to 2000")
,lab3=c("","","","","")
,col1=c(NA,NA,"X1970","X2010","X1970")
,col2=c(NA,NA,"","","X2010")
)
ExTitle <- c("Ex12-Maryland Population-map",
"1970 and 2010 Pop and Change,stag,sn")
grDevices::pdf(file=paste0(TDir,"Ex12-MD Pop 1970 and 2010 plus change-map.pdf"),
width=7.5, height=10.5)
micromapST(mdPopData, panelDesc12,
sortVar=2, ascend=FALSE,
title=ExTitle,
rowNames="full", rowNamesCol='County',
bordGrp="MarylandBG",
axisScale="sn", staggerLab=TRUE,
plotNames="ab")
x <- grDevices::dev.off()
#
### End Example 12
###
#
# micromapST - Example 13 - A linked micromap of the counties
# of the state of New York state using the border group
# "NewYorkDF". The pop/inc data is shown using two dot glyphs,
# an arrow and bar glyph (2010 Population, an arrow showing the
# change in population from 2000 to 2010, Population in 2000,
# and a bar showing the amount of the change.)
#
###
# Load example data from package.
utils::data(nyPopData,envir=environment())
nyPopData$Dif00_10 <- nyPopData$Pop_2010 - nyPopData$Pop_2000
# set up 6 column page layout with colSize
panelDesc13 <- data.frame(
type=c("map","id","dot", "arrow", "dot", "bar")
,lab1=c("", "", "Population in", "Increase from","Pop 2005","Incre")
,lab2=c("", "", "2010", "2000", "", "2000to2010")
,lab3=c("", "", "", "", "", "")
,col1=c(NA, NA, "Pop_2010", "Pop_2000", "Pop_2000","Dif00_10")
,col2=c(NA, NA, "", "Pop_2010", "", "")
,colSize=c(NA,NA, 15, 20, 5, 20)
)
ExTitle <- c("Ex13-New York Population data",
"2010 Pop and since 2000-colSize,sn,stag")
grDevices::pdf(file=paste0(TDir,"Ex13-New York Pop 2010 and Change-sn colSize.pdf"),
width=7.5, height=10.5)
micromapST(nyPopData, panelDesc13,
sortVar="Pop_2000", ascend=FALSE,
title=ExTitle,
rowNames="full",rowNamesCol="Area",
axisScale="sn", staggerLab=TRUE,
bordGrp="NewYorkBG"
)
x <- grDevices::dev.off()
#
#### End Example 13
###
#
# micromapST - Example 14 - A linked micromap of the counties in the
# state of Utah. The UtahPopData data is shown using two dot glypics
# - current population and average increase per area.
#
###
# Load example data from package.
utils::data(UtahPopData,envir=environment())
#
# Get population differences from 2011 to 2001 and 1991.
# Data contains ",". The comma's must be removed and values are
# converted to numbers.
# If data is factors, need to add "as.character()" function
# to the formula below.
UtahPopData2 <- as.data.frame(sapply(UtahPopData,
function(x) gsub(",","",x)),stringsAsFactors=FALSE)
# Calculate the differenct between 2001 and 2011 population.
UtahPopData2$Del1101 <- as.numeric(UtahPopData2$X2011)
- as.numeric(UtahPopData2$X2001)
# Calculate the difference between 1991 and 2001 population.
UtahPopData2$Del0191 <- as.numeric(UtahPopData2$X2001)
- as.numeric(UtahPopData2$X1991)
# set up 5 column page layout
panelDesc14 = data.frame(
type=c("map","id","dot","arrow","arrow")
,lab1=c("","","Population", "2001-2011","Chg 1991-2001")
,lab2=c("","","in 2011","pop change","pop change")
,lab3=c("","","","","")
,col1=c(NA,NA,"X2011","X2011","X2001")
,col2=c(NA,NA,NA,"X2001","X1991")
)
ExTitle <- c("Ex14 - Utah county population 2011",
" and changes last two decades,sn")
grDevices::pdf(file=paste0(TDir,"Ex14-Utah Population.pdf"),
width=7.5,height=10.5)
micromapST(UtahPopData, panelDesc14,
sortVar="X2011", ascend=FALSE,
title=ExTitle,
rowNames="full",rowNamesCol='County',
axisScale="sn",
bordGrp="UtahBG",
plotNames="ab"
)
x <- grDevices::dev.off()
#
### End Example 14
###
#
# micromapST - Example 15 - A linked micromap of the provinces,
# municipalities, autonomous regions and special administrative
# regions of China using the border group of "ChinaDF".
# The ChinaPopInc data is shown using two dot glypics - current
# population and average increase per area.
#
###
utils::data(cnPopData,envir=environment())
# set up 4 column page layout
panelDesc15 = data.frame(
type=c("map","id","dot","bar")
,lab1=c("","","Population", "Population")
,lab2=c("","","in 2013","in 2013")
,lab3=c("","","","")
,col1=c(NA,NA,"pop2013","pop2013")
)
ExTitle <- c("Ex14-China Population",
"in 2013 by area")
grDevices::pdf(file=paste0(TDir,"Ex15-China 2013 Population.pdf"),
width=7.5, height=10.5)
micromapST(cnPopData, panelDesc15,
sortVar="pop2013", ascend=FALSE,
title=ExTitle,
rowNames="full", rowNamesCol='area',
bordGrp="ChinaBG",
plotNames="full")
x <- grDevices::dev.off()
#
### End Example 15
###
#
# micromapST - Example 16 - A linked micromap of the districts
# of the city Seoul South Korea, using the border group of
# "SeoulSKoreaBG". The included SeoulPopData dataset provides
# population and district area statistics for 2012.
# The micromapST generates two glyphics, a sorted dot
# glyphic based on the population and a bar graph based on
# the area.
#
###
# Load example data from package.
utils::data(SeoulPopData,envir=environment())
# set up 4 column page layout
panelDesc16 = data.frame(
type=c("map","id","dot","bar")
,lab1=c("","","Population", "Area")
,lab2=c("","","in 2012","in 2012")
,lab3=c("","","","sqkm")
,col1=c(NA,NA,"Pop.2012","Area")
)
ExTitle <- c("Ex16-Seoul Population",
"in 2012 by district")
grDevices::pdf(file=paste0(TDir,"Ex16-Seoul 2012 Population.pdf"),
width=7.5, height=10.5)
micromapST(SeoulPopData,panelDesc16,
sortVar=3, ascend=FALSE, # sort based on the population
title=ExTitle,
rowNames="full", rowNamesCol='District',
bordGrp="SeoulSKoreaBG",
plotNames="full"
)
x <- grDevices::dev.off()
#
### End Example 16
###
#
# Example 17 - use of Africa population data as data source
# Demonstrates support for vertical oriented geographical
# areas.
#
###
# Load example data from package.
utils::data(AfricaPopData,envir=environment())
panelDesc17 <- data.frame(
type = c("map", "id", "dot", "dot", "dot"),
lab1 = c("", "","Population","Percentage Of","Est x2 Time"),
lab3 = c("", "","People", "Total", "Years"),
col1 = c(NA, NA,"Projection","PercOf", "Est2Time")
)
ExTitle <- c("Ex17-Africa Population Data",
"Sorted by Population on 11x17")
grDevices::pdf(file = paste0(TDir,"Ex17-Africa Micromap-11x17.pdf"),
width = 11, height = 17)
micromapST(AfricaPopData, panelDesc17,
sortVar = "Projection", ascend = TRUE,
title = ExTitle,
rowNames = "ab", rowNamesCol = "Abbr",
bordGrp = "AfricaBG" )
x <- grDevices::dev.off()
#
### End Example 17
###
unlink(TDir)