i want to create a map of the US in R with the states color coded in a heat map type of way based on a metric. I know how to do this using the googleVis api but i can't use the code and without the rollovers it's not that great. what is the quickest way to get this done? i'm familiar with the maps package but i can't get the colors to cooperate. i believe this is called a choropleth map.
heatmap() function in R Language is used to plot a heatmap. Heatmap is defined as a graphical representation of data using colors to visualize the value of the matrix.
The most basic way to map data in R is to create a regular ggplot object and map longitude to the x aesthetic and latitude to the y aesthetic. You can use this technique to create maps of geographic areas, like states or countries, and to map locations as points, lines, and other shapes.
Geographic heat maps are a type of visualization that displays the geographic distribution of data, typically using color or shading. Heat maps are generally used to represent data where the geographic location of items is important.
To create a world map using it we will use the geom_map() function of the ggplot2 package of the R Language. This function returns a ggplot object so all the functions that work on other ggplot plots will be working in geom_map() too. where, data: determines the data be displayed in this layer.
There is a complete example in the ggplot2 package, see ?map_data
.
library(ggplot2)
example(map_data)
(hopefully answer may still be helpful for somebody)
RevolutionAnalytics has excellent example of map visualization using spplot()
function. Here's image from there:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With