Visualizing Mapping Population in R I have data of texas conties and their population from Census Bureau. The population is in 1000’s. I am interested in mapping the different counties in Texas on the map.
Method
1.I will load my csv file which contains Texas counties and their population into the console 2. I will then go ahead and plot a graph using the csv file
texas<-read.csv("texas.csv")
head (texas)
## long lat group order state county pop bin
## 1 -95.75271 31.53560 1 1 texas anderson 56474 < 1e5
## 2 -95.76989 31.55852 1 2 texas anderson 56474 < 1e5
## 3 -95.76416 31.58143 1 3 texas anderson 56474 < 1e5
## 4 -95.72979 31.58143 1 4 texas anderson 56474 < 1e5
## 5 -95.74698 31.61008 1 5 texas anderson 56474 < 1e5
## 6 -95.72405 31.63873 1 6 texas anderson 56474 < 1e5
library(ggplot2)
qplot(long,lat, data = texas)
qplot(long,lat, data = texas, geom = "polygon",group=group)
My friend asked me for the list of all the counties on the map of the United States. Here you go, my friend!
library(maps)
counties<-map_data("county")
qplot(long,lat, data = counties, geom = "polygon",group=group, fill=group)
Finally, I am going to apply the same principle of mapping the US counties on the US map to the Texas counties on Texas map. Here we go!
tx<-qplot(long,lat, data = texas, geom = "polygon",group=group, fill=bin)
tx
However, this graph is not attractive. It doesn’t even have a tittle. So, I am going to give it a title and make it more prettier!
tx+ggtitle("Population of Texas Counties")+coord_map()+scale_fill_brewer("Blues")
In the nutshell, I have taken data from the census bureau about the population of counties in Texas and put them on the map of Texas.