Guest post by Krishna Prasad
As a business analyst using R, one has often stumbled across situations for visually representing the data on a map. Here are some common scenarios:
· Represent the most densely populated cities on a Map
· Showing the cheapest places to live in
· Where can one buy a home with the cheapest home Insurance
These common spatial representation problems can now be solved using the GGMap Integration with R. GGMap is a spatial visualization package for R to show visual data & models on top of Google Map, Open Street Maps or Cloud Maps.
In the below case study, we are going to use Home Insurance Rates Data & use GGMap with R to show home insurance prices for the most populated cities in the US. For example, Chicagos Home Insurance rates are $860 and will be represented in a smaller circle than Houston whose home insurance rates are $960.
Here is the sample data fields for us to improve into our data package:
· Home Insurance Location
· Population
· Home Insurance Rates
· Latitude
· Longtitude
All these above data fields along with the values can be saved in a CSV file called Average_Home_Insurance.csv. This is the file that can be used to import into our GGMap package to visually represent the data.
Here are the extremely simple steps to import, install & show the data on the map.
#Reading the Home Insurance Data from File
>mapdata<-read.csv("average_home_insurance.csv",header=T)
>install.packages("ggmap")
>install.packages("mapproj")
>library(ggmap)
>library(mapproj)
>map<- get_map(location = 'US', zoom = 4)
>ggmap(map)
> TC <-ggmap(map)+geom_point(data=mapdata,alpha = .7, aes(x=longitude, y=latitude,size =Home.Insurance),color='red')+ggtitle("Average Home Insurance By City($)")
> TC
As the above map screenshot shows, each of the circles are represented with various sizes in the map. In your local package, one can also zoom in at various levels to see close by locations & their home insurance rates. For e.g. in the above map, one can zoom into Texas to see the home insurance rates for Dallas, Houston & Austin.
The above case study was done using Google Maps, but one can also use OpenStreetMaps if you wanted more customization on the markers and definitions.
===
This case study is by vHomeInsurance (www.vhomeinsurance.com) a home insurance rates & quotes data analysis service
ggmap is a new tool which enables such visualization by combining the spatial information of static maps from Google Maps, OpenStreetMap, Stamen Maps or CloudMade Maps with the layered grammar of graphics implementation of ggplot2The library is developped by David Kahle and Hadley Wickham and in the latest R/Journal (Volume…
When I attended usrR! 2012 last month, there was an interesting presentation by Dr. David Kahle about the package ggmap. It is a package built over ggmap2 and helps us map spatial data over online maps like Google maps or Open Street Maps. I decided to give ggmap package a…
This post is a brief follow-up to a question that appeared some time ago on the “The R Project for Statistical Computing” LinkedIn group, which I’m reporting here: How can I draw a map of MODERN Europe? Hi, I'm trying … Continue reading →