Book Image

Applied Data Visualization with R and ggplot2

By : Dr. Tania Moulik
Book Image

Applied Data Visualization with R and ggplot2

By: Dr. Tania Moulik

Overview of this book

Applied Data Visualization with R and ggplot2 introduces you to the world of data visualization by taking you through the basic features of ggplot2. To start with, you’ll learn how to set up the R environment, followed by getting insights into the grammar of graphics and geometric objects before you explore the plotting techniques. You’ll discover what layers, scales, coordinates, and themes are, and study how you can use them to transform your data into aesthetical graphs. Once you’ve grasped the basics, you’ll move on to studying simple plots such as histograms and advanced plots such as superimposing and density plots. You’ll also get to grips with plotting trends, correlations, and statistical summaries. By the end of this book, you’ll have created data visualizations that will impress your clients.
Table of Contents (10 chapters)

Maps


Sometimes, we want to know the trends and behaviors of people in different countries or states. For example, we might want to see the shopping behaviors of people in different states. The maps package is useful for this purpose. In this section, we will look at how to draw and display information with maps.

 

 

Displaying Information with Maps

In this section, we'll create a map of the US and Europe that is colored according to lat, long, and group variables. Let's begin by implementing the following steps:

  1. Install the maps package using map_data to get a data frame for the different states' information, as follows:
states_map <- map_data("state")
glimpse(states_map)
## Observations: 15,537
## Variables: 6
## $ long <dbl> -87.46201, -87.48493, -87.52503, -87.53076, -87.5708...
## $ lat <dbl> 30.38968, 30.37249, 30.37249, 30.33239, 30.32665, 30...
## $ group <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
## $ order <int> 1, 2, 3, 4, 5, 6, 7, 8, 9,...