STAT 200 – Introductory Statistics
December 24, 2025
After today’s lecture, you should:
create the following univariate graphics for numeric variables:
create the following bivariate graphics for numeric variables:
modify graphics to make them presentation-worthy
To read into R the data we will use for this lecture, run the following code:
This will read the dataset in from Dr. Forsberg’s website.
If the .csv file is on your computer, use read.csv("file path"), i.e.
read.csv reads the .csv file into as a data frame.
Once again, there are three main packages to use while plotting in R:
base (This is the built-in package in R.)gridggplotThey all use a different way of thinking about how graphics should be created. grid and ggplot are packages that can be added to base R, and can make prettier plots.
We will discuss the base R functions in this lecture.
How should we think about our process for creating plots?
The univariate graphics we will discuss are:
A symmetric distribution is one which looks the same on both sides if split in half.
This is approximate; no real life distributions will ever be perfectly symmetric.
If a distribution is not symmetric, we call that distribution skewed.
Skewed distributions have long “tails” extending out in one direction.
If the tail is extending out to the left, we say the distribution is left (or negatively) skewed.
If the tail is extending out to the right, we say the distribution is right (or positively) skewed.
The bivariate graphics we will discuss are:
We’ll start by making a couple of vectors to plot:
pch =)lty =)lwd =)type =)Suppose we want to make a plot like this. How can we make something this fancy?
1par(mar=c(4,4,1,1))
2par(family="serif", font.lab=2)
3par(cex.lab=1.2, cex.axis=0.8)
4par(xaxs="i", yaxs="i")
5par(las=1)Note that this will start a generic window of that size/dimension.
Again, some graphing functions have their own “starting* functions. So, in those cases, the above two lines are not needed.
1abline(lm(vcrime00~gspcap90), lwd=3, col="purple")
abline(lm(vcrime00~gspcap90), lwd=1, col="pink")
2points(gspcap90 ,vcrime00 , pch=21, bg="lightblue")
3axis (1); axis (2)
title(xlab="GSP per Capita (1990)")
title(ylab="Violent Crime Rate (2000)")
4text(gspcap90[24],vcrime00[24], label=scode[24], pos=3)
text(gspcap90[50],vcrime00[50], label=scode[50], pos=1)All this comes together to produce:
RNote that maps are especially difficult to make, but well worth the effort for geographical data.
Properly making maps is an art form.
There are a lot of features of maps that need to be considered when plotting.
Because of this, maps are especially difficult in any program, even in R.
RThere are several packages that help in map creation.
plotlyspsfRIf you’re feeling adventurous (or picky), we can use R’s strength.
One can modify any image as you want. Thus, starting with a map and modifying it is an option. It is rarely easy, but it is possible, and may be well worth it.
You can even create maps from scratch, adding several features to them to increase the data density.
Here is a map of the four census regions using plotly:
Here is a map of the violent crime rate in 2000 using plotly:
Here is a map Dr. Forsberg made from scratch. I’m not sure how he did this, I’ll have to bug him!