######
# micromapST - Example # 1 - map with no cumulative shading,
# 2 columns of statistics: dot with 95\% confidence interval, boxplot
# sorted in descending order by state rates
####
# load sample data, compute boxplot
data(wflung00and95,wflung00and95US,wflung00cnty)
wfboxlist = boxplot(split(wflung00cnty$rate,wflung00cnty$stabr),plot=FALSE)
# set up 4 column page layout
panelDesc <- 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,wflung00and95US[1,1],NA),
refTexts=c(NA,NA,'US Rate 2000-4',NA),
panelData= c('','','','wfboxlist')
)
# set up PDF output file, call package
FDir <- getwd()
FName <- paste(FDir,"/EX1-WFLung-2000-2004-State-Dot-County-Box.pdf",sep="")
pdf(file=FName,width=7.5,height=10)
micromapST(wflung00and95,panelDesc,sortVar=1,ascend=FALSE,
title=c("White Female Lung Cancer Mortality, 2000-2004",
"State Rates & County Boxplots"))
dev.off()
##End Example 1
######
# micromapST - Example # 2 - map with cumulative shading
# from top down (mapcum), arrow and bar charts,
# sorted in descending order by starting
# value of arrows (1950-69 rates)
####
# Load example data from package.
data(wmlung5070,wmlung5070US)
panelDesc <- 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('','','Deaths per 100,000','Percent'),
col1=c(NA,NA,'RATEWM_50','PERCENT'),
col2=c(NA,NA,'RATEWM_70',NA)
)
FDir <- getwd()
FName <- paste(FDir,"/EX2-wmLung50-70-Arrow-Bar.pdf",sep="")
pdf(file=FName,width=7.5,height=10)
micromapST(wmlung5070,panelDesc,sortVar=1,ascend=FALSE,
title=c("Change in White Male Lung Cancer Mortality Rates",
"from 1950-69 to 1970-94"))
dev.off()
##End Example 2
######
# micromapST - Example # 3 - Time Series Line Plots with Confidence Bands
# maptail option highlights states from extremes to middle state
# read in time series data set example
####
data(TSdata)
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)
panelDesc <- 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('Time Series with Confidence bands',
'Annual Female Lung Cancer Mortality Rates, 1996-2010')
FDir <- getwd()
FName <- paste(FDir,'/EX3-Time-Series-with-Conf.pdf',sep="")
pdf(file=FName,width=7.5,height=10)
micromapST(temprates,panelDesc,sortVar=15,ascend=FALSE,title=ExTitle)
dev.off()
# end of example 3
######
# micromapST - Example 4 - 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)
####
data(TSdata)
temprates <- data.frame(TSdata[,,2]) # create simple matrix of rates for dot panel & sorting
panelDesc <- 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( "Dot Plot for 1996, Scatter Plot Comparing 1996 to 2010",
"Female Lung Cancer Mortality Rates")
FDir <- getwd()
FName <- paste(FDir,"/EX4-Scatter-Dots.pdf",sep="")
pdf(file=FName,width=7.5,height=10)
micromapST(temprates,panelDesc,sortVar=1,ascend=FALSE,title=ExTitle)
dev.off()
##End Example 4
######
# micromapST - Example 5 - 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
####
data(statePop2010)
panelDesc <- 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')
)
FDir <- getwd()
FName <- paste(FDir,"/EX5-Stkd-Bar-variableheight.pdf",sep="")
pdf(file=FName,width=7.5,height=10)
micromapST(statePop2010,panelDesc,sortVar=6,ascend=FALSE,
title=c("Stacked Bars: 2010 Census Pop by Race, Sorted by Percent Other Race",
"Categories Left to Right: Hispanic, non-Hispanic White, Black, Other"))
dev.off()
## End Example 5
######
# micromapST - Example 6 - 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
####
data(Educ8thData)
# columns = State abbrev, State name, Avg Score, \%s \<basic,
# basic, proficient, advanced
panelDesc <- 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("Stacked Bars: Educational Progress (NAEP) in Math, 2011, 8th Grade",
"Centered at Not Proficient vs. Proficient")
FDir <- getwd()
FName <- paste(FDir,"/EX6-Educ-Centered-Bar.pdf",sep="")
pdf(file=FName,width=7.5,height=10)
micromapST(Educ8thData,panelDesc,sortVar=3, title=ExTitle)
dev.off()
rm(Educ8thData)
### End of example 6
######
# micromapST - Example 7 - 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
#
# Turning off the variable bar height and the midpoint dot features
# in the horizontal stacked bars (segmented)
#
####
data(statePop2010)
panelDesc = 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')
)
ExFile = "/EX7-Stkd-Bar-fixedheight-nodot"
FDir = getwd()
FName = paste(FDir,ExFile, ".pdf",sep="")
pdf(file=FName,width=7.5,height=10)
micromapST(statePop2010,panelDesc,sortVar=6,ascend=FALSE,
title=c("Stacked Bars: 2010 Census Pop by Race, Sorted by Percent Other Race",
"Categories Left to Right: Hispanic, non-Hispanic White, Black, Other"),
details=list(SNBar.Middle.Dot=FALSE,SNBar.varht=FALSE))
dev.off()
## End Example 7
Run the code above in your browser using DataLab