
This video provides an overview of the entire course.
Creating professional looking plots, both static and interactive, may seem hard; however, with R we can create and fully customize plots with a few lines of code.
• Use ggplot2 that can produce beautiful plots with a few lines of code
• Plots are fully customizable; to obtain perfect plots every time, use customizable plots.
• Create complex results using interactive plots
Often, beginners fail to properly understand their dataset before analyzing it. However, a good understanding of the origin and structure of the data is of primary importance.
• Introduce the data provider, that is, EPA.
• Understand the EPA network of stations
• A detailed description of the data structure
It is not always good to import data in R using the default settings. For doing it successfully, several parameters need to be set.
• Set the working directory
• Understand the important setting of the function read.table
• Import the data and check the structure
Importing Excel tables in R may be tricky. However, with the right explanation the proper package can be installed and everything should work out fine.
• Install the package xlsx
• Understand the format of the code to import Excel files
• Import and check the data
Exporting data in R may seem difficult, since we have many options to choose from. However, R has powerful exporting functions that with few options can do the job successfully.
• Firstly, we need to subset our data to have something to export
• Then, we can learn how to export data in R
• The final step would be exporting data into multiple Excel sheets
Producing elegant plots in ggplot2 may seem difficult but it is actually quite easy to do. In fact, ggplot2 takes care, by default, of most of the graphical design of the plot, meaning that we can produce beautiful histograms with just a few lines of code.
• Load ggplot2 and then import the dataset
• Plot a simple histogram, using the default settings.
• Plot multiple distributions with faceting
Histograms are useful for certain tasks, but for comparing several variables at once they are not the best. Box plots can be used instead, since they allow the comparison of the distribution of multiple variables side by side.
• Explain what a box plot is and what does it represents
• Create multiple box plots with just two lines of code
• Order the plot to achieve better results
Categorical variables are invariably difficult to visualize in meaningful ways. Bar charts are important for plotting categorical variables and defining their characteristics.
• Learn bar charts
• Create simple bar charts in ggplot2
• Learn how to automatically order a data.frame and plot ordered bar charts
In many cases, we are interested in comparing multiple variables at once and checking their correlation. Scatterplots allow us to do just that and are an important tool in a data analyst's toolbox.
• Describe the importance of scatterplots
• Create simple scatterplots in ggplot2
• Create more complex visualization by tweaking some basic options
In many cases, the variable time is underestimated. However, time-series are extremely useful to determine the temporal pattern of a variable.
• Understand the structure of time-series plots
• Plot a simple time-series plot in ggplot2
• Customize the plots with color and size
Many datasets are affected by uncertainty and people not always know how to show this in plots. This video will present ways to solve this and take uncertainty into account.
• Understand how to handle uncertainty
• Present simple ways to include uncertainty in bar-charts
• Present the scatterplots with double error bars
By default, ggplot2 creates plots with a grayish background, and without axes lines and white gridlines. This is not the standard look you normally find in scientific manuscripts.
• Explain the graphical elements of the standard theme
• Change the default theme
• Explore the differences between the default theme and the others
The default color scale is not always appropriate to spot all the differences in the data we are trying to plot. In many cases, we have to change it so that our plots can become more informative.
• Change the default two colors for plotting continuous variables
• Explore ways to include more colors in the color scale
• Present discrete color scale for categorical variables
ggplot2 uses the names of the columns as labels, meaning that if these are not self-explanatory, the plot will not provide a good framework to understand its meaning. By adding some lines of code, we can customize the plot in order to change the labels and make it clearer.
• Add a title for the plot
• Change the title of the legend
• Change the axes labels
The default plots created by ggplot2 lack several elements that in many cases are useful to provide additional information to viewers. However, there are simple functions that can be used to add supplementary elements to the plot.
• Add the trend lines to scatterplots
• Learn how to add vertical and horizontal lines to plots
• Customize the lines
In many cases, it is crucial to be able to include textual labels on plots to provide viewers with additional information. This can be done in ggplot2 in both static and dynamic ways.
• Add fixed text labels
• Add dynamic textual labels
• Add text outside the plot and change the axis labels
With the function facet_wrap, it is only possible to create a grid of plots of the same type. However, in some cases, it is necessary to create side-by-side graphs with diverse plots. This can be done in the package gridExtra.
• Review the facet_wrap function
• Install the gridExtra package
• Create the multi plots
We could easily save our plots as images directly from R Studio. This way of saving however, does not provide much flexibility. If we want to customize our images, we need to learn how to export plots from the R code.
• Create an object with the plot we want to save
• Learn the basics of the ggsave function
• Change the size of the image
The default size that ggplot2 uses to save plots is ideal for most of our needs, such as embedding plots in Word documents. However, in some cases, we may need to specify a particular page size for our plots, which can be easily done with the option paper.
• Specify the page size
• Rotate the page
• Specify other options
Static plots are the standard for publishing in traditional media, such as journal papers. However, the world is moving towards an internet-based presentation of results and even scientific journals are quickly adapting it. Many now offer the possibility of including interactive plots. In R, we can create plots for the Web with the rCharts package, which is a bit more difficult to install than ggplot2.
• Explain the rCharts package
• Install devtools
• Install rCharts from GitHub
rCharts features a syntax more similar to standard plotting in R than what we saw with ggplot2. However, it is easy to pick up by showing simple examples and then including additional details.
• Explain the syntax of rCharts
• Include more details
• Add JavaScript functions for more flexibility
Even though we know nothing about HTML and CSS, we can still obtain beautiful bar-charts using templates created by other users.
• Plot basic interactive bar charts
• Add axis labels
• Use a template for an elegant finish
If too many data points are present in our dataset, scatterplot visualization may become very confusing in static plots. However, in interactive plots this limitation no longer applies, since we can select to visualize only some datasets.
• Create basic interactive scatterplots
• Understand the interactivity
• Add elements and controls
Time-series plots are a great way to visualize the temporal pattern of a variable. However, sometimes we cannot fully understand the exact date of each point based only on the values on the x axis. Interactive visualization can solve this problem by adding tooltips in which we can take a look at the raw data.
• Set the data in the correct format
• Plot a basic time-series plot
• Add elements
Shiny is a package to build fully featured websites from scratch in R. The way it communicates between the user interface and the server may seem difficult to understand. However, with some explanation, understanding Shiny becomes very easy and intuitive.
• Introduce the Shiny package
• Explain the tutorial and examples
• Understand the basic structure of a Shiny website
Understanding the structure of a Shiny website is very important. However, presenting it from a website is not enough for the viewers to replicate it. Therefore, in this video, we are going to create a simple website with data and plots we already used, to further help viewers.
• Understand the basic structure of Shiny
• Add elements to UI and Server
• Test the website
If we plan to upload our Shiny website on-line, we need to implement a way for users to upload their own data. In this video, we are going to show how to do just that.
• Importing files in Shiny
• Simple code to do it
• Add a separator for more flexibility
One of the key components of a successful website is the ability to respond to users’ interactions. This can be achieved with conditional panels, which change the UI based on users’ interactions.
• Explain conditional panels
• Understand UI modifications
• Apply server modifications
One of the key components of a successful website is the ability to respond to users’ interactions. This can be achieved with conditional panels, which change the UI based on users’ interactions.
• Modify server side modifications
• Keep track of the IDs
• Recognize variables automatically
So far, we have looked at ways to create and add elements to a Shiny website. However, sooner or later, this website needs to be deployed on the Internet so that everybody can use it. Here, you will learn how to do it using a free account on shinyapps.io.
• Separate ui.r and server.r
• Add plots to the script
• Finally, we deploy the site.
This video gives an overview of the entire course.
R comes loaded with some basic packages, but the R community is rapidly growing and active R users are constantly developing new packages for R.
Install a package
Load the package
Everything in R is in the form of objects. Objects can be manipulated in R.
Generate a vector numeric, character and complex
Detect missing values
Remove the NA values
We will dive into R's capability with regard to matrices and edit (add, delete, or replace) elements of a matrix.
Define a vector using the c() notation
Generate a transpose
Edit (add, delete, or replace) the elements
One of the useful and widely used functions in R is the data.frame() function.
Create a matrix and convert it into a data frame
Add and remove columns and rows
Reorder the columns of a data frame
Once we have processed our data, we need to save it to an external device or send it to our colleagues. It is possible to export data in R in many different formats.
Import a CSV fie
Export data from R
Most of the tasks in R are performed using functions. A function in R has the same utility as functions in Arithmetic.
Open a new R script by navigating to File
Write a function that accepts two values and adds these values
Write a function that makes use of the if else logic
If we want to perform an action repeatedly in R, we can utilize the loop functionality.
Multiply each element of x and y
Define a matrix in R
R has some very handy functions, such as apply, sapply, tapply, and mapply, that can be used to reduce the task of writing complicated statements.
Implement the apply function
Use the lapply function
Perform the tapply function
One quick and easy way to edit a plot is by generating the plot in R and then using Inkspace or any other software to edit it.
Set the background color
Change the orientation of the labels
Specify the color of the labels
Scatter plots are used primarily to conduct a quick analysis of the relationships among different variables in our data.
Attach the data using the attach() function
View the data and plot the data
Add a legend using the legend() function
We will display multivariate data on a scatter plot and also introduce interactive scatter plots.
Install and load the googleVis package and import data
Construct a new data frame
Generate an interactive scatter plot
The advantage of using the Google Chart API in R is the flexibility it provides in making interactive plots.
Install the googleVis package
Load a library and import data
Generate an interactive bar plot
Line plots are simply lines connecting all the x and y dots. They are very easy to interpret and are widely used to display an upward or downward trend in data.
Generate a line plot
Import the fertility data
Construct a line object
Gantt charts are used to track the progress of a project displayed against time.
Import data
Redefine a new data frame
Generate an object
Plot a histogram using the googleVis package and merge more than one histogram on the same page.
Install the googleVis package
Generate the histograms
Combine the two gvis objects in one browser
The advantage of the Google Chart API is the interactivity and the ease with which they can be attached to a web page.
Install and load the googleVis package
Construct our bubble chart
View both the bubble plots side by side
The waterfall plots or staircase plots are observed mostly in financial reports.
Import the waterf.csv data file
Construct the Waterfall plot
This video helps you get introduced to the concept of dendrograms.
Define the start of random numbers
Bind the column
Generate the scatterplot and dendrogram
This video teaches you to create a plot which is easy to study and more informative.
Use the dendroextras package
Change the view from rectangle to triangle
Plot a three-dimensional dendrogram
Heat maps are a visual representation of data, wherein each value in a matrix is represented with a color. This video shows you how to create a heat map.
Install and load the pheatmap package
Import data in the matrix form
Plot heatmap
This video dives into plotting a heat map by customizing colors.
Install the packages
Construct the color palette
Define the color scheme
This video teaches you to integrate a dendrogram and heat map into a single plot.
Install and import packages
Import data and scale it
Perform PCA in R
R allows us to plot three-dimensional interactive heat maps using the heat map package.
Install Neatmap
Clean the data
Plot stereo
Tree maps are basically rectangles placed adjacent to each other. The size of each rectangle is directly proportional to the data being used in the visualization.
Install and load the package
Import data and store it as data frame
Create a tree object in R
We encounter maps on a daily basis, be it for directions or to infer information regarding the distribution of data. Maps have been widely used to plot various types of data in R.
Install and load the googleVis package
Import the debt.csv data file
Generate the visualization
Choropleth maps can be state level as well as county level. In this video, we will plot well-being data on a state level.
Install and load the googleVis package
Import the well-being.csv data file
Generate the plot
Contour maps are used to display data related to temperature or topographic information.
Specify the range of colors
Define our color palette
Generate a contour map
For each region, a bubble or a pie chart is used that represents percentage.
Import the ghg.csv fie
Examine the data
Specify the size of the bubble
Overlaying maps with text is not a very prominent medium of displaying information.
Import the name.csv data file
Use the [i] notation to plot
Use a loop to plot all the 50 names
The shapefile package in R can be used to read a shapefile, add the processed data to our shapefile, and then save it in the shapefile format.
Open our dataset
Select all the columns
Select the Format option
The idea of a cartogram is to show the gravity of the issue or data being studied.
Click on Add layer
Navigate to the folder
Click on Create cartogram
Pie charts are a great visualization technique to represent data and help viewers understand statistical data.
Create a vector and calculate percentages
Create a pie using the pie() function
Labels are important as they give the information about the sections of the pie chart. We will include labels inside the pie chart in this video.
Create a label and pie chart using the floating.pie() function
Add legends and view the pie chart
Donut charts have advantages over pie charts with respect to the area and efficiency in visualizing information.
Install the plotrix package
Create a pie chart and draw a circle in the center to convert it into a donut chart
Instead of using multiple pie charts for comparing data, we can use slope charts.
Import data
Create a slope chart using the bumpchart() function
Fan plots are an alternative to pie charts and are useful in differential and comparative analysis.
Construct a fan plot using the fan.plot() function
Make changes to the chart and view the final plot
This video gives overview of the entire course.
Adding a third dimension to the existing plot helps in revealing information and portraying data from a newer angle.
Install Plot3D package
Load the package
Generate a scatter plot
Applying text to a plot is the additional functionality of the plot3D package
Install and load the plot3D package
Define the column names as row names
Plot the actual text in 3D
In this video we will generate simple 3D Pie Chart using Plotrix package.
Install and load the plotrix package
Define a character vector – col
Apply pie 3D labels function
In this video, we will plot a 3D Histogram.
Generate data for the x and y values
Generate the histogram using hist3D function
Plot a ribbon plot
In this video, we will explore about implementation of 3D contours in R.
Create a layout for our image
Generate dataset for the x and y values
Construct four different contour plots
In this video, we will learn to plot a contour map in 3D using the plot3D package in R.
Generate some data to construct our plots
Generate four different plots
Plot an interactive contour map
In this video, we will learn to surface plots and animation in R.
Use an animation package
Define the m, n, and o variables
Use the surf3D() function to construct
When the density of data increases in a particular region of a plot, it becomes hard to read. So in this video, the sunflower plots are used as variants of scatter plots to display bivariate distribution.
Load the Galton data
Examine the headers and first six observations
Construct a sunflower plot
The hexagon-shaped bins were introduced to plot densely packed sunflower plots.
Implement the rnorm() function
Generate a hexbin plot
Use the generic R plot() function
Calendar plots have been used to display data on a daily or monthly basis, where each square represents a data point.
Create a character vector
Use the data.frame() function
Plot the calendar plot
In this video, we will implement the alternative methods to visualize multivariate data that is by using Chernoff faces.
Load the ‘aplpack’ data file
Examine the format and column headers and explore the data
Generate Chernoff faces
In this video, we will construct the coxcomb plot.
Utilize the HistData and plotrix packages
Load the Nightingale data file
Generate the coxcomb plot
In this video, we will study the basics of creating a network plot using a random dataset.
Install the igraph package
Generate fake data and import it
Create a network graph object
In this video, we will use oil prices in USA as an example to construct the radial plot.
Install the package and load the library
Import the oil.csv data file
Construct a radial plot
You might have seen these plots in news or journal articles and wondered how to create them quickly. This video will help you accomplish this task.
Install and load the packages
Load the CSV file
Create a pyramid plot
Candlestick plots are widely used to display time series data related to financial markets.
Install and load the quantmod package
Import MSFT and FB data files
Generate a candlestick plot
We will learn an easy way to generate an interactive version of the same plot.
Download data in XTS format
Convert our data to the data frame format
Generate candlestick plot object
The main objective of this section is to introduce the concept of decomposition.
Import the data as a CSV file
Decompose a series
Change the model to multiplicative
Regression lines are a visual representation of the regression equation.
Load data using the ISLR package
Generate the intercept and the estimate for horsepower
Construct the plot
The Flowing Data website provides a very detailed description on how to read a box plot.
Set the margin of the plot
Construct a simple box plot
In the violin plot, we can observe the mean, which is displayed using white dots, and the dispersion of various variables.
Install and load the ISLR and vioplot packages
Construct a plot using the vioplot function
R comes with some basic methods to test for normality, such as the Shapiro test.
Test the null hypothesis
Generate a simple QQ plot
In this video, we will utilize the density() function to generate a plot.
Download the data using the getSymbols() function
Estimate the kernel density using the density() function
Plot a density plot over the histogram
Correlation plots are a great tool to visualize correlation data.
Download the data as a data frame
Generate the correlation matrix
Pass the fxcor object as an argument
In this video, we will study how to quickly generate a word cloud in R.
Install and load wordcloud, tm, Rcolorbrewer packages
Define the range of color palettes
Generate a word cloud
In this video, we will learn how to create a word cloud using an entire document.
Apply readline function to read the file that contains the text
Clean and structure the text document
Create a word cloud by simply using wordcloud package
A comparison cloud works on the same principles as a word cloud.
Generate a corpus using the Corpus() function
Clean our text document and utilize the removeWords() function to eliminate stop words
Constructs a term document matrix
In this video, we will learn some important matrix functions that allow us to further conduct text analysis and also generate a correlation plot.
Clean the text and use the same functions
Generate a correlation object
Create a correlation plot
The main aim of this video is to introduce you to installing fonts and how to use them to label plots.
Load the xkcd fonts
Create fake data for our chart
Display the plot using the plot() function
The idea behind generating an XKCD-style plot is to bring the same humor to our plot.
Customize the fonts
Create fake data for the plot
Construct the plot by adding the theme
Animating a visualization brings a new dimension to our visualization.
Install and load the googleVis package
Download the data and import the data using read.csv() function
Generate the googleVis object
One of the issues while creating presentations using PowerPoint is that we have to manually update the data, contents, and plot.
Install and load solidify and devtools packages
Create an index.rmd file
Open a file called index.rmd
In this section, we will get the basic introduction to API and XML.
Click on the API Console section
Select Real Estate API from the drop-down menu
Create a link with all the information
In this video, we will construct a bar plot using XML data.
Import the data directly in R
Parse the XML data
Construct and structure the data, and plot a bar plot
The shiny package allows us to create applications in R.
Install and load the shiny package
Execute the runApp("shiny") function
Generate the main panel with the output plot
Effective visualization helps you get better insights from your data, make better and more informed business decisions! R is one of the most widely used open source languages for data and graph analysis. It is platform-independent and allows users to load various packages as well as develop their own packages to interpret data better. R gives aspiring analysts and data scientists the ability to represent complex sets of data in an impressive way. So, if you're a data science professional and want to learn about the powerful data visualization techniques of R, then go for this Learning Path.
This comprehensive 3-in-1 course follows a practical approach, where each recipe presents unique functions of plots, charts, and maps as well as visualization of 2D and 3D interactive plots in a step-by-step manner! You’ll begin with generating various plots in R using the basic R plotting techniques. Utilize R packages to add context and meaning to your data. Finally, you'll design interactive visualizations and integrate them on your website or blog!
By the end of the course, you’ll master the visualization capabilities of R to build interactive graphs, plots, and Pie charts as well as visualize 2D and 3D interactive plots.
Contents and Overview
This training program includes 3 complete courses, carefully chosen to give you the most comprehensive training possible.
The first course, Learning R for Data Visualization, covers getting to grips with R’s most popular packages and functions to create interactive visualizations for the web. We start by importing data in R from popular formats such as CSV and Excel tables. Then you will learn how to create basic plots such as histograms, scatterplots, and more, with the default options, which guarantees stunning results. In the final part of the course, the Shiny package will be extensively discussed. This allows you to create fully-featured web pages directly from the R console, and Shiny also allows it to be uploaded to a live website where your peers and colleagues can browse it and you can share your work. You will see how to build a complete website to import and plot data, plus we will present a method to upload it for everybody to use. Finally, you will revise all the concepts you've learned while having some fun creating a complete website.
By the end of the course, you will have an armor full of different visualization techniques, with the capacity to apply these abilities to real-world data sets.
The second course, R Data Visualization - Basic Plots, Maps, and Pie Charts, covers mastering the visualization capabilities of R to build interactive graphs, plots, and Pie. We start - off with the basics of R plots and an introduction to heat maps and customizing them. After this, we gradually take you through creating interactive maps using the googleVis package. Finally, we generate choropleth maps and contouring maps, bubble plots, and pie charts.
The third course, R Data Visualization - Word Clouds and 3D Plots, covers advanced visualization techniques in R to build word clouds, 3D plots, and more. We start off with the basics of R plots and an introduction to heat maps and customizing them. After this, we gradually take you through creating interactive maps using the googleVis package. Finally, we generate choropleth maps and contouring maps, bubble plots, and pie charts.
By the end of the course, you’ll master the visualization capabilities of R to build interactive graphs, plots, and Pie charts as well as visualize 2D and 3D interactive plots.
About the Authors
Fabio Veronesi obtained a Ph.D. in digital soil mapping from Cranfield University and then moved to ETH Zurich, where he has been working for the past three years as a postdoc. In his career, Dr. Veronesi worked at several topics related to environmental research: digital soil mapping, cartography, and shaded relief, renewable energy and transmission line siting. During this time Dr. Veronesi specialized in the application of spatial statistical techniques to environmental data.
Atmajit Singh Gohil works as a senior consultant at a consultancy firm in New York City. After graduating, he worked in the financial industry as a Fixed Income Analyst. He writes about data manipulation, data exploration, visualization, and basic R plotting functions on his blog. He has a master's degree in financial economics from the State University of New York (SUNY), Buffalo. He also graduated with a Master of Arts degree in economics from the University of Pune, India. He loves to read blogs on data visualization and loves to go out on hikes in his free time.