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)

Preface

This book introduces you to the world of data visualization by talking about the basic features of ggplot2. Learn all about setting up the R environment and then begin exploring features of ggplot2. Grammar of graphics and geometric objects are the fundamentals you must know before you dive deep into the plotting techniques. Read and discover what are layers, scales, coordinates, and themes, and explore how you can use them to transform your data into aesthetical graphs. Learn the simple plots, such as histograms, and then some advanced plots, such as superimposing plots and density plots. Learn to plot trends, correlations, and statistical summaries. After reading this book, your data visualizations will wow clients.

After completing this book, you will be able to:

  • Set up the R environment, RStudio, and explain structure of ggplot2
  • Distinguish types of variables and use best practices to visualize them
  • Change visualization defaults to reveal more information about data
  • Implement the grammar of graphics in ggplot2 such as scales and faceting
  • Build complex, aesthetic visualizations with ggplot2 analysis methods
  • Logically and systematically explore complex relationships
  • Compare variables in a single visual, with advanced plotting methods

Who This Book Is For

This book is meant for professionals, who work with data and R, and for students, who want to enhance their data analysis skills by adding informative and professional visualizations. We assume that readers know basics of the R language, its commands, and objects.

What This Book Covers

Chapter 1, Basic Plotting in ggplot2, will help you to understand Kubernetes patterns which would be presented with the examples from Kubernetes itself and external applications.

Chapter 2, Grammar of Graphics and Visual Components, will help you to cover accessing Kubernetes API with raw HTTP queries to complex libraries with both in-cluster and out-cluster examples.

Chapter 3, Advanced Geoms And Statistics, will present extension capabilities of Kubernetes with custom resource definitions, custom controllers, dynamic admission controllers, and custom schedulers.

To Get the Most out of This Book

For an optimal experience, we recommend the following hardware configuration:

  • Processor: Intel Core i5 or equivalent
  • Memory: 4GB RAM
  • Storage: 35 GB available space

You'll also need the following software installed in advance:

  • OS: Windows 7 SP1 64-bit, Windows 8.1 64-bit, or Windows 10 64-bit
  • Browser: Google Chrome, Latest Version
  • Installing R
  1. To install the R package and libraries, go to http://cran.us.r-project.org/ in your browser.
  2. Click on Download R for Windows, click on base, then click on Download R 3.5.0 for Windows (or any newer version that appears). 
  3. Install R. Leave all default settings as they are in the installation options.
  • Installing RStudio:
  1. To install RStudio, go to http://rstudio.org/download/desktop.
  2. Choose the default installation.
  3. Open RStudio after installation. It uses the underlying R package and will open it automatically in the IDE.

Download the Example Code Files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/TrainingByPackt/Applied-Data-Visualization-with-R-and-ggplot2. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Conventions Used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Use the ggplot(df_vanc,aes(x=Vancouver)) + geom_bar() command to obtain the following chart."

A block of code is set as follows:

df_t <- read.csv("data/historical-hourly-weather-data/temperature.csv")
ggplot(df_t,aes(x=Vancouver))+geom_histogram()
ggplot(df_t,aes(x=Miami))+geom_histogram();

Activity: These are scenario-based activities that will let you practically apply what you've learned over the course of a complete section. They are typically in the context of a real-world problem or situation.

Note

Warnings or important notes appear like this.

Get in Touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.

Note

All the solutions to the activities are present in the Appendix section.