+ - 0:00:00
Notes for current slide
Notes for next slide

Data Visualization/Plotting

Zulquar Nain

AMU

2025-05-16

Plotting

Image:BoldBI

Visualization

Data visualization is the process to transform the information (data) into a visual presentation for example graph.

Visualization

Data visualization is the process to transform the information (data) into a visual presentation for example graph.

Why visualisation/Plotting?

Visualization

Data visualization is the process to transform the information (data) into a visual presentation for example graph.

Why visualisation/Plotting?

An image speaks louder than words

Visualization

Data visualization is the process to transform the information (data) into a visual presentation for example graph.

Why visualisation/Plotting?

An image speaks louder than words

Data visualizations make data easier for the human brain to understand

Visualization

Data visualization is the process to transform the information (data) into a visual presentation for example graph.

Why visualisation/Plotting?

An image speaks louder than words

Data visualizations make data easier for the human brain to understand

visualization also makes it easier to detect patterns, trends, and outliers in groups of data

Visualization

Data visualization is the process to transform the information (data) into a visual presentation for example graph.

Why visualisation/Plotting?

An image speaks louder than words

Data visualizations make data easier for the human brain to understand

visualization also makes it easier to detect patterns, trends, and outliers in groups of data

Good data visualizations should place meaning into complicated datasets so that their message is clear and concise.

Visualization

Data visualization is the process to transform the information (data) into a visual presentation for example graph.

Why visualisation/Plotting?

An image speaks louder than words

Data visualizations make data easier for the human brain to understand

visualization also makes it easier to detect patterns, trends, and outliers in groups of data

Good data visualizations should place meaning into complicated datasets so that their message is clear and concise.

According to Tableau, “[data visualization is] one of the most useful professional skills to develop. The better you can convey your points visually, the better you can leverage that information.”

Visualization/Ploting in R

Visualization/Ploting in R

Visualisation / Plotting is one of greatest strength of R

Visualization/Ploting in R

Visualisation / Plotting is one of greatest strength of R

Limited scope of this course

Visualization/Ploting in R

Visualisation / Plotting is one of greatest strength of R

Limited scope of this course

Visualization/Ploting in R

Visualisation / Plotting is one of greatest strength of R

Limited scope of this course

Basic plot function in R is plot()

Each graph function has - number of options

Visualization/Ploting in R

Visualisation / Plotting is one of greatest strength of R

Limited scope of this course

Basic plot function in R is plot()

Each graph function has - number of options

grpahical parameters par()

Ingredients for plotting

Ingredients for plotting

Data

Materials to visualise that is data. No data no visualisation!

Ingredients for plotting

Data

Materials to visualise that is data. No data no visualisation!

Mapping: Contextual relationship

Mapping depends on what YOU want to show!

Data

Data

Import

Data

Import

We have learned in previous lectures

Data

Import

We have learned in previous lectures

Mapping

Data

Import

We have learned in previous lectures

Mapping

We will learn!

Data

Import

We have learned in previous lectures

Mapping

We will learn! A basic graph

Data

Import

We have learned in previous lectures

Mapping

We will learn! A basic graph

plot(cars$speed, cars$dist, pch = 19, col = 'red', las = 1, xlab="speed", ylab="Distance", main = "Speed Vs Distance")

Plotting- Setting

We will use inbuild data sets in R

Plotting- Setting

We will use inbuild data sets in R

To view available datasets in R Type data() and execute

Plotting- Setting

We will use inbuild data sets in R

To view available datasets in R Type data() and execute

We will primarily use data(cars)

Plotting- Setting

We will use inbuild data sets in R

To view available datasets in R Type data() and execute

We will primarily use data(cars)

Most used function for plotting in R is plot()

Plotting- Setting

We will use inbuild data sets in R

To view available datasets in R Type data() and execute

We will primarily use data(cars)

Most used function for plotting in R is plot()

Data-Cars

data(cars)

Data-Cars

data(cars)

Examining the data

Data-Cars

data(cars)

Examining the data

Do you remember? head() ; tail() ; nrow()

Data-Cars

data(cars)

Examining the data

Do you remember? head() ; tail() ; nrow()

head(cars, 2)
## speed dist
## 1 4 2
## 2 4 10
tail(cars, 2)
## speed dist
## 49 24 120
## 50 25 85

Data-Cars

data(cars)

Examining the data

Do you remember? head() ; tail() ; nrow()

head(cars, 2)
## speed dist
## 1 4 2
## 2 4 10
tail(cars, 2)
## speed dist
## 49 24 120
## 50 25 85
ncol(cars)
## [1] 2
str(cars)
## 'data.frame': 50 obs. of 2 variables:
## $ speed: num 4 4 7 7 8 9 10 10 10 11 ...
## $ dist : num 2 10 4 22 16 10 18 26 34 17 ...

Let's start- Plot()

data(cars) contains two variables speed and distance

Let's start- Plot()

data(cars) contains two variables speed and distance

First plot

Plotting speed and distance

Let's start- Plot()

data(cars) contains two variables speed and distance

First plot

Plotting speed and distance

plot(cars$speed,cars$dist)

Let's start- Plot()

data(cars) contains two variables speed and distance

First plot

Plotting speed and distance

plot(cars$speed,cars$dist)

  • Here, cars$speed is for x-axis and cars$dist is for y-axis

  • In cars$speed, cars is name of the data file and speed is variable name

  • plot() is command to plot

Let's start- Plot()

Second plot

Let's start- Plot()

Second plot

# output-location: fragment
x <- seq(-pi,pi,0.1)
plot(x, sin(x))

Let's start- Plot()

Second plot

# output-location: fragment
x <- seq(-pi,pi,0.1)
plot(x, sin(x))

  • Here x is for x-axis (a generated data using seq command )

  • sin(x) is for y-axis

Let's start- Plot()

Adding label and Title

plot(cars$speed, cars$dist,
xlab = "Speed", ylab = "Distance", main = "Speed Vs Distance" )

Let's start- Plot()

Adding label and Title

plot(cars$speed, cars$dist,
xlab = "Speed", ylab = "Distance", main = "Speed Vs Distance" )

  • Here to add the label, we have added the highlighted codes.

  • Names of the label should always be in ""

Let's start- Plot()

Changing Color and Plot Type

  • We can change the plot type with the argument type
"p" - points
"l" - lines
"b" - both points and lines
"c" - empty points joined by lines
"o" - overplotted points and lines
"s" and "S" - stair steps
"h" - histogram-like vertical lines
"n" - does not produce any points or lines
plot(x, sin(x),
main="The Sine Function",
ylab="sin(x)",
type="l" )

Let's start- Plot()

Changing Color and Plot Type

  • Similarly, we can define the colors using col="color name"

Let's start- Plot()

Changing Color and Plot Type

  • Similarly, we can define the colors using col="color name"
plot(cars$speed, cars$dist,
xlab = "Speed", ylab = "Distance", main = "Speed Vs Distance",
col="red" )

Let's start- Plot()

Changing Color and Plot Type

  • Similarly, we can define the colors using col="color name"
plot(cars$speed, cars$dist,
xlab = "Speed", ylab = "Distance", main = "Speed Vs Distance",
col="red" )

Let's start- Plot()

Changing Color and Plot Type

  • Similarly, we can define the colors using col="color name"
plot(cars$speed, cars$dist,
xlab = "Speed", ylab = "Distance", main = "Speed Vs Distance",
col="red" )

  • See the highlighted part of the code

Some Baisc Graphs

R Bar Plot

Some Baisc Graphs

R Bar Plot

  • Let's assume AR contains data of average rainfall in a day of a week.

Some Baisc Graphs

R Bar Plot

  • Let's assume AR contains data of average rainfall in a day of a week.
AR <- c( 12, 15, 11, 16, 18, 15, 14 )
barplot(AR)

Some Baisc Graphs

R Bar Plot

  • Let's assume AR contains data of average rainfall in a day of a week.
AR <- c( 12, 15, 11, 16, 18, 15, 14 )
barplot(AR)

  • There are many other parameters can be added to barplot()

  • Use ?barplot() to explore

Some Baisc Graphs

R Bar Plot

Some Baisc Graphs

R Bar Plot

  • Some of the parameters are added here.

Some Baisc Graphs

R Bar Plot

  • Some of the parameters are added here.
barplot(AR,
main = "Average rainfall in a Day",
xlab = "Centimeters (cm)",
ylab = "Day",
names.arg = c("Mon", "Tues", "Wed", "Thu", "Fri", "Sat", "Sun"),
border="blue",
col="red",
density=20,
horiz = TRUE,
cex.names = .8)#To change the size of label

Some Baisc Graphs

R Bar Plot

  • Some of the parameters are added here.
barplot(AR,
main = "Average rainfall in a Day",
xlab = "Centimeters (cm)",
ylab = "Day",
names.arg = c("Mon", "Tues", "Wed", "Thu", "Fri", "Sat", "Sun"),
border="blue",
col="red",
density=20,
horiz = TRUE,
cex.names = .8)#To change the size of label
  • See the highlighted codes

  • Output in next slide

Some Baisc Graphs

R Bar Plot

Some Baisc Graphs

R Bar Plot

  • Some of the parameters are added here.

Some Baisc Graphs

R Bar Plot

  • Some of the parameters are added here.

Some Baisc Graphs

Bar Plot of Categorical Data

Some Baisc Graphs

Bar Plot of Categorical Data

  • For example marks out of 20 of ten students in Math is in vector MM
## [1] 17 16 18 17 18 19 18 16 18 18

Some Baisc Graphs

Bar Plot of Categorical Data

  • For example marks out of 20 of ten students in Math is in vector MM
## [1] 17 16 18 17 18 19 18 16 18 18
  • Simple bar plot

Some Baisc Graphs

Bar Plot of Categorical Data

  • For example marks out of 20 of ten students in Math is in vector MM
## [1] 17 16 18 17 18 19 18 16 18 18
  • Simple bar plot

  • Does it serve pupose?

Some Baisc Graphs

Bar Plot of Categorical Data

  • For example marks out of 20 of ten students in Math is in vector MM
## [1] 17 16 18 17 18 19 18 16 18 18
  • Simple bar plot

  • Does it serve pupose?

  • No

Some Baisc Graphs

Bar Plot of Categorical Data

  • First convert the data into categorical representation using table()

  • Check out ?table()

table(MM)
## MM
## 16 17 18 19
## 2 2 5 1

Some Baisc Graphs

Bar Plot of Categorical Data

  • First convert the data into categorical representation using table()

  • Check out ?table()

table(MM)
## MM
## 16 17 18 19
## 2 2 5 1
barplot(table(MM),
main="Marks of 10 Students",
xlab="Marks",
ylab="Count",
border="blue",
col="red",
density=10
)

Some Baisc Graphs

Bar Plot of Categorical Data

  • First convert the data into categorical representation using table()

  • Check out ?table()

table(MM)
## MM
## 16 17 18 19
## 2 2 5 1
barplot(table(MM),
main="Marks of 10 Students",
xlab="Marks",
ylab="Count",
border="blue",
col="red",
density=10
)

Some Baisc Graphs

Bar Plot of Categorical Data

Some more Bar plot

Some Baisc Graphs

Bar Plot of Categorical Data

Some more Bar plot

print(titanic_surv)
## train.Pclass
## train.Survived 1 2 3
## 0 80 97 372
## 1 136 87 119
  • Here, 1, 2, and 3 represents 1st, 2nd and 3rd class in the train

  • 0 and 1 is for the passenger did not survived and survived respectively in the Titanic mishap

barplot(titanic_surv,
main = "Survival of Each Class",
xlab = "Class",
ylab = "No of Passenger",
col = c("red","green")
)
legend("topleft",
c("Not survived","Survived"),
fill = c("red","green")
)

Some Baisc Graphs

Bar Plot of Categorical Data

Some more Bar plot

Some Baisc Graphs

Histogram-hist()

Some Baisc Graphs

Histogram-hist()

  • Histogram is a visual representation of the distribution of a dataset

  • We will use the data(AirPassengers) in built in R

  • Explore the function hist() using ?hist()

  • A Basic Histogram

  • put the name of your dataset in between the parentheses like hist(AirPassengers)

  • Histogram for a specific variable can be drawn as hist(datasetName$VariableName)

Some Baisc Graphs

Histogram-hist()

  • Histogram is a visual representation of the distribution of a dataset

  • We will use the data(AirPassengers) in built in R

  • Explore the function hist() using ?hist()

  • A Basic Histogram

  • put the name of your dataset in between the parentheses like hist(AirPassengers)

  • Histogram for a specific variable can be drawn as hist(datasetName$VariableName)

hist(AirPassengers)

Some Baisc Graphs

Histogram-hist()

  • Other parameters of hist()
hist(AirPassengers,
main="Histogram for Air Passengers",
xlab="Passengers",
border="blue",
col="green",
xlim=c(100,700),
las=1,
breaks=5)

Some Baisc Graphs

Histogram-hist()

  • Other parameters of hist()
hist(AirPassengers,
main="Histogram for Air Passengers",
xlab="Passengers",
border="blue",
col="green",
xlim=c(100,700),
las=1,
breaks=5)

  • xlim=c() & ylim=c() fixes the range of X and Y axes

  • Inside c() sets starting and ending points

  • las=1 rotates the label of Y-axis Checkout ?las

  • breaks is for the size/width of Histogram BINS Chechout ?breaks

Some Baisc Graphs

Pie Chart-Pie Chart

Some Baisc Graphs

Pie Chart-Pie Chart

  • Pie chart is drawn using the pie() function in R programming

  • This function takes in a vector of non-negative numbers.

  • Basic Syntax of is pie(x, labels, radius, main, col, clockwise)

  • x is a vector containing the numeric values used in the pie chart.

  • labels is used to give description to the slices.

  • radius indicates the radius of the circle of the pie chart.(value between −1 and +1).

  • main indicates the title of the chart.

  • col indicates the color palette.

  • clockwise is a logical value indicating if the slices are drawn clockwise or anti clockwise.

  • Explore ?pie()

Some Baisc Graphs

Pie Chart-Pie Chart

Some Baisc Graphs

Pie Chart-Pie Chart

  • In pie(), scores$Obt.Marks is the vector of positive numbers for which pie-chart is drawn

  • scores$Subjects is the labels

  • Note: scores$Subjects shows that Subjects variable has been selected fromscores dataset

  • Pie Chart
pie(scores$Obt.Marks, scores$Subjects)

  • Data
print(scores)
## Subjects Obt.Marks
## 1 Math 70
## 2 Eng 80
## 3 Urdu 60
## 4 Sc 80
## 5 Soc. 90

Some Baisc Graphs

Pie Chart-Pie Chart

Other parameters

piepercent<- round(100*(scores$Obt.Marks)/sum((scores$Obt.Marks)), 1) # %age calculation
pie(scores$Obt.Marks, labels = piepercent, # Labels
main = "Scores pie chart", # Title of chart
col = rainbow(length(scores$Obt.Marks))) # Color of chart
legend("topright", # legend position
scores$Subjects, # legend labels
cex = 0.8, # size of legend texts
fill = rainbow(length(scores$Obt.Marks))) # legend color

Some Baisc Graphs

Scatterplot Matrix

  • In case of more than two variables and to find the correlation between one variable versus the remaining ones

  • we use scatterplot matrix. pairs() function creates matrices of scatterplots.

  • pairs(formula, data)

  • We will use data(mtcars) available within R; explor ?mtcars

## mpg cyl disp hp drat wt qsec vs am gear carb
## Mazda RX4 21 6 160 110 3.9 2.620 16.46 0 1 4 4
## Mazda RX4 Wag 21 6 160 110 3.9 2.875 17.02 0 1 4 4
pairs(~wt+mpg+disp+cyl,data = mtcars,
main = "Scatterplot Matrix")
  • Plot in the next slide

Some Baisc Graphs

Scatterplot Matrix

  • Plot in the next slide

Multiple Plots

R Function par()

  • For drawing multiple graphs in a single plot- use par()

  • Checkout ?par()

Multiple Plots

R Function par()

  • For drawing multiple graphs in a single plot- use par()

  • Checkout ?par()

Let's take an example

Multiple Plots

R Function par()

  • For drawing multiple graphs in a single plot- use par()

  • Checkout ?par()

Let's take an example

  • For drawing two graphs in one plot
par(mfrow=c(1,2)) # set the plotting area into a 1*2 array (1 Row and 2 Col)
barplot(scores$Obt.Marks, names.arg = scores$Subjects, main="Barplot", las=2) # Bar plot
pie(scores$Obt.Marks, scores$Subjects, main="Piechart", radius=1) # Pie Chart
  • See the graph in next slide

Multiple Plots

R Function par()

  • For drawing multiple graphs in a single plot- use par()

  • Checkout ?par()

Let's take an example

  • For drawing two graphs in one plot
par(mfrow=c(1,2)) # set the plotting area into a 12 array (1 Row and 2 Col)
barplot(scores$Obt.Marks, names.arg = scores$Subjects, main="Barplot", las=2) # Bar plot
pie(scores$Obt.Marks, scores$Subjects, main="Piechart", radius=1) # Pie Chart
  • See the graph in next slide
  • Here parameter mfrow used to specify the number of subplot we need.

Multiple Plots

R Function par()

  • For drawing multiple graphs in a single plot- use par()

  • Checkout ?par()

Let's take an example

  • For drawing two graphs in one plot
par(mfrow=c(1,2)) # set the plotting area into a 12 array (1 Row and 2 Col)
barplot(scores$Obt.Marks, names.arg = scores$Subjects, main="Barplot", las=2) # Bar plot
pie(scores$Obt.Marks, scores$Subjects, main="Piechart", radius=1) # Pie Chart
  • See the graph in next slide
  • Here parameter mfrow used to specify the number of subplot we need.

  • It takes in a vector of form c(m, n) which divides the given plot into m*n array of subplots.

Multiple Plots

R Function par()

  • For drawing multiple graphs in a single plot- use par()

  • Checkout ?par()

Let's take an example

  • For drawing two graphs in one plot
par(mfrow=c(1,2)) # set the plotting area into a 12 array (1 Row and 2 Col)
barplot(scores$Obt.Marks, names.arg = scores$Subjects, main="Barplot", las=2) # Bar plot
pie(scores$Obt.Marks, scores$Subjects, main="Piechart", radius=1) # Pie Chart
  • See the graph in next slide
  • Here parameter mfrow used to specify the number of subplot we need.

  • It takes in a vector of form c(m, n) which divides the given plot into m*n array of subplots.

  • For the above example, to plot the two graphs side by side, we have m=1 and n=2.

Multiple Plots

R Function par()- Explore it for more control parameters

Saving / Exporting Graph

  • All types of graphs (bar plot, pie chart, histogram) etc. can be saved.

  • Graphs can be saved as bitmap image( i.e. .png, jpeg, tiff etc) which are fixed size

  • Graphs can be also saved as vector image (.pdf, .eps) which are easily resizable

  • We will use the temperature column of built-in dataset airquality

Saving / Exporting Graph

Saving as .jpeg

jpeg(file="saving_plot1.jpeg")
# File name
hist(Temp, col="darkgreen")
dev.off() # TO call off

Saved Graph

Saving / Exporting Graph

Saving as .jpeg

jpeg(file="saving_plot1.jpeg")
# File name
hist(Temp, col="darkgreen")
dev.off() # TO call off

Saved Graph

  • Image will be saved in working/default directory

  • we need to call the function dev.off() after all the plotting, to save the file and return control to the screen

  • The resolution of the image by default will be 480×480 pixel.

Saving / Exporting Graph

Saving as .png

png(file= "saving_plot2.png",
width=600, height=350)
hist(Temp, col="gold")
dev.off()

Saved Graph

  • You can specify the full path tp save the image at desired plcae (as above)

  • You can also specify the resolution at desired level using arguments width and height

Saving / Exporting Graph

Saving as .bmp

  • Size of the plot can be specified in different units such as in inch, cm or mm with the argument units and ppi with res.

  • The following code saves a bmp file of size 6x4 inch and 100 ppi.

bmp(file="saving_plot3.bmp",
width=6, height=4, units="in", res=100)
hist(Temp, col="steelblue")
dev.off()

Saved Graph

Saving / Exporting Graph

Saving as .pdf

bmp(file="saving_plot4.pdf",
width=6, height=4, units="in", res=100)
hist(Temp, col="violet")
dev.off()

Saving / Exporting Graph

Saving as .pdf

bmp(file="saving_plot4.pdf",
width=6, height=4, units="in", res=100)
hist(Temp, col="violet")
dev.off()

Saved Graph

Plotting in R

Plotting in R

  • This presentation is not exhaustive.

Plotting in R

  • This presentation is not exhaustive.

  • Adopt learning by doing approach

Plotting in R

  • This presentation is not exhaustive.

  • Adopt learning by doing approach

  • Make use of Google and R Documentation

Plotting in R

  • This presentation is not exhaustive.

  • Adopt learning by doing approach

  • Make use of Google and R Documentation

  • It was about basic R plotting

Plotting in R

  • This presentation is not exhaustive.

  • Adopt learning by doing approach

  • Make use of Google and R Documentation

  • It was about basic R plotting

  • Plotting has become more exciting and easy using package-ggplot2 in R

--

Some More Basic Grpahs

Histogram and Density Plot

Some More Basic Grpahs

Histogram and Density Plot

  • Simple Histogram

Some More Basic Grpahs

Histogram and Density Plot

  • Simple Histogram
hist(mtcars$mpg,
breaks = 10,col="red")
  • The option breaks= controls the number of bins.

Some More Basic Grpahs

Histogram and Density Plot

  • Simple Histogram
hist(mtcars$mpg,
breaks = 10,col="red")
  • The option breaks= controls the number of bins.

Some More Basic Grpahs

Histogram and Density Plot

Some More Basic Grpahs

Histogram and Density Plot

  • Histograms can be a poor method for determining the shape of a distribution because it is so strongly affected by the number of bins used.

Some More Basic Grpahs

Histogram and Density Plot

  • Histograms can be a poor method for determining the shape of a distribution because it is so strongly affected by the number of bins used.

  • Kernal density plots are usually a much more effective way to view the distribution of a variable

Some More Basic Grpahs

Histogram and Density Plot

  • Histograms can be a poor method for determining the shape of a distribution because it is so strongly affected by the number of bins used.

  • Kernal density plots are usually a much more effective way to view the distribution of a variable

d <- density(mtcars$mpg) # returns the density data
plot(d) # plots the results

Some More Basic Grpahs

Histogram and Density Plot

  • Histograms can be a poor method for determining the shape of a distribution because it is so strongly affected by the number of bins used.

  • Kernal density plots are usually a much more effective way to view the distribution of a variable

d <- density(mtcars$mpg) # returns the density data
plot(d) # plots the results

Some More Basic Grpahs

Dot Plots

Some More Basic Grpahs

Dot Plots

dotchart(mtcars$mpg,
labels=row.names(mtcars),
cex=.7,
main="Gas Milage 4 Car Models",
xlab="Miles Per Gallon")

Some More Basic Grpahs

Dot Plots

dotchart(mtcars$mpg,
labels=row.names(mtcars),
cex=.7,
main="Gas Milage 4 Car Models",
xlab="Miles Per Gallon")

Some More Basic Grpahs

Dot Plots

Some More Basic Grpahs

Dot Plots

  • Dotplot: Grouped Sorted and Colored

Some More Basic Grpahs

Dot Plots

  • Dotplot: Grouped Sorted and Colored

  • Sort by mpg, group and color by cylinder

Some More Basic Grpahs

Dot Plots

  • Dotplot: Grouped Sorted and Colored

  • Sort by mpg, group and color by cylinder

x <- mtcars[order(mtcars$mpg),] # sort by mpg
x$cyl <- factor(x$cyl) # it must be a factor
x$color[x$cyl==4] <- "red"
x$color[x$cyl==6] <- "blue"
x$color[x$cyl==8] <- "darkgreen"
dotchart(x$mpg,labels=row.names(x),cex=.7,groups= x$cyl,
main="Gas Milage for Car Models\ngrouped by cylinder",
xlab="Miles Per Gallon", gcolor="black", color=x$color)

Some More Basic Grpahs

Dot Plots

  • Dotplot: Grouped Sorted and Colored

  • Sort by mpg, group and color by cylinder

x <- mtcars[order(mtcars$mpg),] # sort by mpg
x$cyl <- factor(x$cyl) # it must be a factor
x$color[x$cyl==4] <- "red"
x$color[x$cyl==6] <- "blue"
x$color[x$cyl==8] <- "darkgreen"
dotchart(x$mpg,labels=row.names(x),cex=.7,groups= x$cyl,
main="Gas Milage for Car Models\ngrouped by cylinder",
xlab="Miles Per Gallon", gcolor="black", color=x$color)

Line Plot

A basic Line Plot

x <- 1:10 # Create example data
y1 <- c(3, 1, 5, 2, 3, 8, 4, 7, 6, 9)
plot(x, y1, type = "l",
main = "This is my Line Plot",
xlab = "My X-Values",
ylab = "My Y-Values")

Line Plot

A basic Line Plot

x <- 1:10 # Create example data
y1 <- c(3, 1, 5, 2, 3, 8, 4, 7, 6, 9)
plot(x, y1, type = "l",
main = "This is my Line Plot",
xlab = "My X-Values",
ylab = "My Y-Values")

Line Plot

Changing width of line

x <- 1:10 # Create example data
y1 <- c(3, 1, 5, 2, 3, 8, 4, 7, 6, 9)
plot(x, y1, type = "l",
lwd= 5,
main = "This is my Line Plot",
xlab = "My X-Values",
ylab = "My Y-Values")

Line Plot

Changing width of line

x <- 1:10 # Create example data
y1 <- c(3, 1, 5, 2, 3, 8, 4, 7, 6, 9)
plot(x, y1, type = "l",
lwd= 5,
main = "This is my Line Plot",
xlab = "My X-Values",
ylab = "My Y-Values")

Line Plot

Multiple Line Plot to one graph

x <- 1:10 # Create example data
y1 <- c(3, 1, 5, 2, 3, 8, 4, 7, 6, 9)
y2 <- c(5, 1, 4, 6, 2, 3, 7, 8, 2, 8)
y3 <- c(3, 3, 3, 3, 4, 4, 5, 5, 7, 7)
plot(x, y1, type = "l",
lwd= 5,
main = "This is my Line Plot",
xlab = "My X-Values",
ylab = "My Y-Values")
lines(x, y2, type = "l", col = "red")
lines(x, y3, type = "l", col = "green")
legend("topleft",
legend = c("Line y1", "Line y2", "Line y3"),
col = c("black", "red", "green"),
lty = 1)

Line Plot

Multiple Line Plot to one graph

x <- 1:10 # Create example data
y1 <- c(3, 1, 5, 2, 3, 8, 4, 7, 6, 9)
y2 <- c(5, 1, 4, 6, 2, 3, 7, 8, 2, 8)
y3 <- c(3, 3, 3, 3, 4, 4, 5, 5, 7, 7)
plot(x, y1, type = "l",
lwd= 5,
main = "This is my Line Plot",
xlab = "My X-Values",
ylab = "My Y-Values")
lines(x, y2, type = "l", col = "red")
lines(x, y3, type = "l", col = "green")
legend("topleft",
legend = c("Line y1", "Line y2", "Line y3"),
col = c("black", "red", "green"),
lty = 1)

Box Plot

Box Plot

  • box plot gives us a visual representation of the quartiles within numeric data

Box Plot

  • box plot gives us a visual representation of the quartiles within numeric data

  • box plot shows the median (second quartile), first and third quartile, minimum, and maximum

Box Plot

  • box plot gives us a visual representation of the quartiles within numeric data

  • box plot shows the median (second quartile), first and third quartile, minimum, and maximum

Box Plot

A Box plot

boxplot(mpg~cyl,data=mtcars,
main="Car Milage Data",
xlab="Number of Cylinders",
ylab="Miles Per Gallon")

Box Plot

A Box plot

boxplot(mpg~cyl,data=mtcars,
main="Car Milage Data",
xlab="Number of Cylinders",
ylab="Miles Per Gallon")

Box Plot

Box Plot: Adding color

boxplot(mpg~cyl,data=mtcars,
col= c("cyan","blue","steelblue"),
main="Car Milage Data",
xlab="Number of Cylinders",
ylab="Miles Per Gallon")

Box Plot

Box Plot: Adding color

boxplot(mpg~cyl,data=mtcars,
col= c("cyan","blue","steelblue"),
main="Car Milage Data",
xlab="Number of Cylinders",
ylab="Miles Per Gallon")

THANKS

Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow