Plotting Dot Plot

For plotting the dot plot we are going to the geom_point function present in the ggplot2 package which plots the relationship between two continuous variables.

R




library(tidyverse)
mpg %>%
  ggplot(aes(x=manufacturer, y=displ, color = year))+
  labs(title = "Paired dot plot and box plot")+
  geom_point()


Output:

In the above code, we added the geom_point() function which will draw the dot plot of the data. We also mapped the color aesthetic to the year attribute in the mpg data set which will ensure that every year will have a unique color. The information about which year is mapped to which color is depicted on the right side of the graph.

Plot Paired dot plot and box plot on same graph in R

R Programming Language is used for statistical computing and graphics. R was first developed at the University of Auckland by two professors Ross Ihanka and Robert Gentleman

Similar Reads

Dot Plot

The dot plot is a graphical representation of how one attribute varies with respect to another attribute. On the x-axis, we usually plot the attribute with respect to which we want to track the variation, and on the y-axis, you plot the value whose variation we want to see. Suppose you are given a set of data with attribute height and width and you want to see how width varies with respect to height. Then you can plot the height on the x-axis and width on the y-axis....

Box Plot

A box plot is a graphical representation of the data which gives a five-number summary of the data: Minimum, First Quarter (Q1), Median, Second Quarter(Q2), and Maximum. They are mainly used for visualizing the distribution of the data....

Importing Data

We are going to use the mpg dataset that will be loaded when we install the ggplot2 package. To install ggplot2 we need to install the tidyverse package which consists of 8 core packages and ggplot2 is one of them. Copy and paste the below code in the terminal for installing tidyverse :...

Defining Aesthetics

...

Plotting Dot Plot

Aesthetics are the properties of the graph that is used to customize the graph according to the requirements. Examples of various aesthetics are the x-axis, y-axis, color, shape, etc. For plotting the graph we are going to use the ggplot function available in the ggplot2 package. We will be mapping the manufacturer attribute in mpg to the x-axis and the display attribute to the y-axis....

Plotting box plot

...

Plotting dot plot and box plot on the same graph using mpg dataset

For plotting the dot plot we are going to the geom_point function present in the ggplot2 package which plots the relationship between two continuous variables....

Plotting the dot plot and box plot on the same graph using iris dataset

...

Plotting dot plot and box plot on the same data using the Orange dataset

For plotting the dot plot we are going to the geom_boxplot function present in the ggplot2 package which plots the distribution of a continuous variable....