top of page

Simple Visualizations

KEY:

ds = dataset you are currently using.

Var = variable to be displayed 

optional, etc. = where any optional commands belong

XYXY <- variable into which data is being saved

Topics:

Common Options

Include these inside of the parenthesis of any of the below visualizations

Label on x-axis: xlab = "Name"

Label on y-axis: ylab = "Name"

Boundaries of x-axis: xlim = c(0, 25)

Boundaries of the y-axis: ylim = c(0, 25)

Title: main = "Figure Title"

Anchor 1

Box Plot

boxplot(ds$VarY ~ ds$VarX, optional, etc.)

Anchor 2

Frequency Bars

barplot(table(ds$Var), optional, etc.)

To add a solid line on the x-axis, include: axis.lty = "solid"

To control space between bars: space = 0.25

Anchor 3

Histogram/Density Plot

hist(ds$Var, optional, etc.)

 

Control the number of bars: breaks = 30

Change to density plot: probability = TRUE

Add pdf line to density plot (separate command): lines(density(ds$Var))

Matrix of histograms

(1) Load psych package: library(psych)

(2) XYXY <- subset(ds, select = c(Var1, Var2, Var3)

(3) multi.hist(data)

Anchor 4

Scatter Plot

plot(ds$VarY ~ ds$VarX, optional, etc.)

 

Change plot markers (see "?pch" in R for a listing: pch = 4)

To change markers to line (e.g., trend line): type = "l"

For a matrix of scatter plots

XYXY <- subset(ds, select = c(Var1, Var2, Var3)

pairs(XYXY)

Anchor 5
Anchor 6

Trend Line

Note: Make sure your data is properly ordered, or the line function will produce an abstract figure.

Y-Axis defined, X-Axis undefined

plot(ds$VarY, type = "l", optional, etc.)

Y- and X- defined (line will connect in order points are defined...X needs to be ordered)

plot(ds$VarY ~ ds$VarX, type = "l", optional, etc.)

Change plot markers (see "?pch" in R for a listing: pch = 4)

bottom of page