R comes with many built-in datasets which are quite useful while learning R. To begin learning the basics of data visualization in R, we will make use of some of these datasets. Datasets in the ‘datasets’ package Many datasets are included in a package called datasets which is distributed with R so these datasets are instantly available […]

# Data Visualization with R

## How to Create a Scatter Plot in R

When you start analyzing a new dataset, your first requirement would be to know the variables in the dataset and the relationship between them. A scatter plot is the perfect place to start with. It is the quickest way to view the relationship between any two variables x and y. You can create a scatter […]

## Create a Scatter Plot in R with Multiple Groups

Let’s say you have Sales Orders data for a sports equipment manufacturer and you want to plot the Revenue and Gross Margins on a scatter plot. However, you also have a ProductLine column that contains information about the product category and you want to distinguish the x,y points by the ProductLine. We can do so […]

## Creating a Bar Chart in R

In R, we can create a bar plot using the barplot() function. A Bar Plot or Bar Graph is primarily used to compare values. It presents grouped data using rectangular bars whose lengths are proportional to the values that they represent. Let’s take our Product Sales data where we have the Revenue and Gross Margin for each […]

## Creating a Line Chart in R

In R, we can create a line plot using the same plot() function by adding a plot type of “l”. This will plot the (x,y) paired observations and connect them with lines. Let’s generate our own data for this lesson. We will use the rnorm() function to generate a set of 100 random numbers that follow a normal distribution. […]

## Plotting Multiple Datasets on One Chart in R

It’s a common scenario to plot multiple datasets together on a single graph. For example, we may want to plot the daily returns from multiple stocks on a single chart to understand how they trend vis-a-vis each other. Similarly, we may want to plot multiple normal distribution curves with different mean and standard deviations. To […]

## Adding Details and Features to R Plots

We’ve already seen how we can enhance the plots created in R by adding title, axis labels, legends, etc. Let’s learn about a few more enhancements. Adding Vertical/Horizontal Lines to the Graph You may want to add a vertical or a horizontal line to your graph at a certain axis point. This can be done […]