R Data Visualization Recipes

Book description

Translate your data into info-graphics using popular packages in R

About This Book

  • Use R's popular packages - such as ggplot2, ggvis, ggforce, and more - to create custom, interactive visualization solutions.
  • Create, design, and build interactive dashboards using Shiny
  • A highly practical guide to help you get to grips with the basics of data visualization techniques, and how you can implement them using R

Who This Book Is For

If you are looking to create custom data visualization solutions using the R programming language and are stuck somewhere in the process, this book will come to your rescue. Prior exposure to packages such as ggplot2 would be useful but not necessary. However, some R programming knowledge is required.

What You Will Learn

  • Get to know various data visualization libraries available in R to represent data
  • Generate elegant codes to craft graphics using ggplot2, ggvis and plotly
  • Add elements, text, animation, and colors to your plot to make sense of data
  • Deepen your knowledge by adding bar-charts, scatterplots, and time series plots using ggplot2
  • Build interactive dashboards using Shiny.
  • Color specific map regions based on the values of a variable in your data frame
  • Create high-quality journal-publishable scatterplots
  • Create and design various three-dimensional and multivariate plots

In Detail

R is an open source language for data analysis and graphics that allows users to load various packages for effective and better data interpretation. Its popularity has soared in recent years because of its powerful capabilities when it comes to turning different kinds of data into intuitive visualization solutions.

This book is an update to our earlier R data visualization cookbook with 100 percent fresh content and covering all the cutting edge R data visualization tools. This book is packed with practical recipes, designed to provide you with all the guidance needed to get to grips with data visualization using R. It starts off with the basics of ggplot2, ggvis, and plotly visualization packages, along with an introduction to creating maps and customizing them, before progressively taking you through various ggplot2 extensions, such as ggforce, ggrepel, and gganimate. Using real-world datasets, you will analyze and visualize your data as histograms, bar graphs, and scatterplots, and customize your plots with various themes and coloring options. The book also covers advanced visualization aspects such as creating interactive dashboards using Shiny

By the end of the book, you will be equipped with key techniques to create impressive data visualizations with professional efficiency and precision.

Style and approach

This book is packed with practical recipes, designed to provide you with all the guidance needed to get to grips with data visualization with R. You will learn to leverage the power of R and ggplot2 to create highly customizable data visualizations of varying complexities. The readers will then learn how to create, design, and build interactive dashboards using Shiny.

Table of contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Conventions
    5. Reader feedback
    6. Customer support
      1. Downloading the example code
      2. Errata
      3. Piracy
      4. Questions
  2. Installation and Introduction
    1. Introduction
    2. Installing and loading graphics packages
      1. How to do it...
      2. How it works...
      3. There's more
      4. See also...
    3. Using ggplot2, plotly, and ggvis
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more
      5. See also
    4. Making plots using primitives
      1. How to do it...
      2. How it works...
      3. There's more...
  3. Plotting Two Continuous Variables
    1. Introduction
    2. Plotting a basic scatterplot
      1. How to do it...
      2. How it works...
      3. There's more...
    3. Hacking ggvis add_axis() function to operate as a title function
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Plotting a scatterplot with shapes and colors
      1. How to do it...
      2. How it works...
    5. Plotting a shape reference palette for ggplot2
      1. How to do it...
      2. How it works...
      3. There's more...
    6. Dealing with over-plotting, reducing points
      1. How to do it...
      2. How it works...
      3. There's more...
    7. Dealing with over-plotting, jittering points
      1. How to do it...
      2. How it works...
    8. Dealing with over-plotting, alpha blending
      1. How to do it...
      2. How it works...
      3. There's more...
    9. Rug the margins using geom_rug()
      1. How to do it...
      2. How it works...
    10. Adding marginal histograms using ggExtra
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Drawing marginal histogram using gridExtra
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Crafting marginal plots with plotly
      1. How to do it...
      2. How it works...
    13. Adding regression lines
      1. How to do it...
      2. How it works...
    14. Adding quantile regression lines
      1. Getting ready
      2. How to do it...
      3. How it works...
    15. Drawing publish-quality scatterplots
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  4. Plotting a Discrete Predictor and a Continuous Response
    1. Introduction
    2. Installing car package and getting familiar to data
      1. How to do it...
      2. How does it works...
      3. There is more
      4. See also
    3. Drawing simple box plots
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Adding notches and jitters to box plots
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Drawing bivariate dot plots using ggplot2
      1. Getting ready
      2. How to do it...
      3. How does it work...
      4. There is more
    6. Using more suitable colors for geom_dotplot
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Combining box with dot plots
      1. Getting ready
      2. How it works...
      3. How it works...
      4. See also
    8. Using point geometry to work as dots using ggvis, plotly and ggplot2
      1. Getting ready...
      2. How it works...
      3. How it works...
      4. There is more
    9. Crafting simple violin plots
      1. How to do it...
      2. How it works...
    10. Using stat_summary to customize violin plots
      1. Getting ready
      2. How it works...
      3. How it works...
      4. There is more...
    11. Manually sorting and coloring violins 
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Using joy package to replace violins
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    13. Creating publication quality violin plots
      1. Getting Ready
      2. How to do it...
      3. How it works...
      4.  See also
  5. Plotting One Variable
    1. Introduction
    2. Creating a simple histogram using geom_histogram()
      1. Getting ready
      2. How to do it...
      3. How does it work...
    3. Creating an histogram with custom colors and bins width
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Crafting and coloring area plots using geom_area() and more
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Drawing density plots using geom_density()
      1. How to do it...
      2. How it works...
      3. See also
    6. Drawing univariate colored dot plots with geom_dotplot()
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Crafting univariate bar charts
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Using rtweet and ggplot2 to plot twitter words frequencies
      1. Getting ready...
      2. How to do it...
      3. How it works...
      4. See also
    9. Drawing publish quality density plot
      1. How to do it...
      2. How it works...
  6. Making Other Bivariate Plots
    1. Introduction
    2. Creating simple stacked bar graphs
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Crafting proportional stacked bar
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Plotting side-by-side bar graph
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Plotting a bar graphic with aggregated data using geom_col()
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Adding variability estimates to plots with geom_errrorbar()
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Making line plots
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Making static and interactive hexagon plots
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There is more...
    9. Adjusting your hexagon plot
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    10. Developing a publish quality proportional stacked bar graph
      1. Getting ready
      2. How to do it...
      3. How it works...
  7. Creating Maps
    1. Introduction
    2. Making simple maps - 1854 London Streets
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Creating an interactive cholera map using plotly
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Crafting choropleth maps using ggplot2
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Zooming in on the map
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Creating different maps based on different map projection types
      1. Getting ready
      2. How to do it... 
      3. How it works...
      4. See also
    7. Handling shapefiles to map Afghanistan health facilities
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Crafting an interactive globe using plotly
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Creating high quality maps
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  8. Faceting
    1. Introduction
    2. Creating a faceted bar graph
      1. How to do it...
      2. How it works...
    3. Crafting faceted histograms
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Creating a facet box plot
      1. How to do it...
      2. How it works...
    5. Crafting a faceted line plot
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There is more
    6. Making faceted scatterplots
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Creating faceted maps
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Drawing facets using plotly
      1. How to do it...
      2. How it works...
      3. See also
    9. Plotting a high quality faceted bar graph
      1. How to do it...
      2. How it works...
  9. Designing Three-Dimensional Plots
    1. Introduction
    2. Drawing a simple contour plot using ggplot2
      1. How to do it...
      2. How it works...
    3. Picking a custom number of contour lines
      1. How to do it...
      2. How it works...
    4. Using the directlabels package to label the contours
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Crafting a simple tile plot with ggplot2
      1. How to do it...
      2. How it works...
    6. Creating simple raster plots with ggplot2
      1. How to do it...
      2. How it works...
      3. There is more
    7. Designing a three-dimensional plot with plotly
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Crafting a publication quality contour plot
      1. How to do it...
      2. How it works...
  10. Using Theming Packages
    1. Introduction
    2. Drawing a bubble plot
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Popular themes with ggthemes
      1. Getting Ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Applying sci themes with ggsci
      1. Getting Ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Importing new fonts with the extrafont package
      1. Getting Ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Using ggtech to mimic tech companies themes
      1. Getting Ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Wrapping a custom theme function
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Applying awesome themes and checking misspells with hrbrthemes
      1. Getting Ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  11. Designing More Specialized Plots
    1. Introduction
    2. Drawing wonderful facets zoom with the ggforce package
      1. Getting Ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Drawing sina plots with ggforce
      1. Getting Ready
      2. How to do it...
      3. How it works...
    4. Using ggrepel to plot non-overlaying texts
      1. Getting Ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Visualizing relational data structures with ggraph
      1. Getting Ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Draw alternative lollipop and density plots with ggalt
      1. Getting Ready
      2. How to do it...
      3. How it works...
      4. See also
  12. Making Interactive Plots
    1. Introduction
    2. Using ggiraph to create interactive plots
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Using gganimate to craft animated ggplots
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Crafting animated plots with tweenr
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  13. Building Shiny Dashboards
    1. Introduction
    2. Installing and loading a shiny package
      1. How to do it...
      2. How it works...
    3. Creating basic shiny interactive plots
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Developing intermediate shiny interactive plots
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Building a shiny dashboard
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also

Product information

  • Title: R Data Visualization Recipes
  • Author(s): Vitor Bianchi Lanzetta
  • Release date: November 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781788398312