This is the exploratory visualizaton behind the Trend CT story: In Connecticut, nearly one in ten have asthma.

Visit the repo for the data used in this analysis. (Also, check out the reproducible scripts and data behind many of our other stories in our central data stories repo)

The data used in this analysis was either imported from the state of Connecticut’s open data portal or downloaded from the Environmental Protection Agency National Air Toxics Assessment site.

What’s in this walkthrough

Several visualizations of asthma-related hospitalizations or emergency treatment as well as air pollutants by census tract.


asthma <- read.csv("", stringsAsFactors=F)

towntracts <- readOGR(dsn="maps", layer="census_tracts")
## OGR data source with driver: ESRI Shapefile 
## Source: "maps", layer: "census_tracts"
## with 833 features
## It has 14 fields
# creating a copy
towntracts_only <- towntracts

# turn the shapefile into a dataframe that can be worked on in R

towntracts <- fortify(towntracts, region="GEOID10")

townborders <- readOGR(dsn="maps", layer="ctgeo")
## OGR data source with driver: ESRI Shapefile 
## Source: "maps", layer: "ctgeo"
## with 169 features
## It has 6 fields
townborders_only <- townborders
townborders<- fortify(townborders, region="NAME10")

#names(asthma)[names(asthma) == 'Census.Tract'] <- 'id'
#asthma$id <- ifelse(nchar(asthma$Census.Tract) ==5, paste0("090010", asthma$Census.Tract), paste0("09009", asthma$Census.Tract))

tracts2towns <- read.csv("data/tracts_to_towns.csv", stringsAsFactors=F)

tracts2towns$id <- str_sub(tracts2towns$tract, 6,10 )
colnames(tracts2towns) <- c("id", "town", "Census.Tract")

asthma$Census.Tract <- as.character(asthma$Census.Tract)

asthma$Census.Tract <- ifelse(nchar(asthma$Census.Tract)==5, asthma$Census.Tract, str_sub(asthma$Census.Tract, 2,6 ))

asthma$ugh <- paste(asthma$Town, asthma$Census.Tract)
tracts2towns$ugh <- paste(tracts2towns$town, tracts2towns$Census.Tract)
tracts2towns$ugh <- str_trim(tracts2towns$ugh)

asthma <- left_join(asthma, tracts2towns, by="ugh")

asthma$id <- as.character(asthma$id)

asthma$id <- paste0("0", asthma$id)

total_map <- left_join(towntracts, asthma, by="id")
total_map$ugh <- NULL
total_map$town <- NULL
total_map$Census.Tract.y <- NULL

total_map2 <- gather(total_map, "category", "n", 10:19)

total_map2$n <- as.numeric(total_map2$n)

tm_ct <- ggplot() +
  geom_polygon(data = total_map2, aes(x=long, y=lat, group=group, fill=n), color = "black", size=0.2) +
  geom_polygon(data = townborders, aes(x=long, y=lat, group=group, fill=total), color = "black", fill=NA, size=0.5) +
  coord_map() +
  facet_wrap(~category, ncol=1) +
  scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=10)) +
  theme_nothing(legend=TRUE) +
  labs(title="Asthma-related emergencies Connecticut 2010-2015", fill="")