DATA VISUALIZATION

Scatter Plot of Two Variables

plot(mtcars$disp, mtcars$mpg, xlab = "Engine Displacement", ylab = "mpg", main = "MPG Compared with Engine Displacement")

Position of ylabel

plot(mtcars$disp, mtcars$mpg, xlab = "Engine Displacement", ylab = "mpg", main = "MPG Compared with Engine Displacement", las = 0)

GGPLOT 2 (Quick Plot)

library(ggplot2)
qplot(disp, mpg, data=mtcars, ylim=c(0,35), geom = "jitter") # Quick Plot

GGPLOT 2 (More Robust)

ggplot(mtcars, aes(x=disp, y=mpg), ylim=0) + geom_line() + geom_point()

BarPlot

barplot(BOD$demand, main = "Graph of Demand", names.arg = BOD$Time)

BarPlot with table of frequencies

cylcount <- table(mtcars$cyl)
barplot(cylcount, main = "Cylinder Count")

Barplot with ggplot2 (Quick Plot)

qplot(factor(mtcars$cyl))

Barplot with ggplot2 (Robust Plot)

ggplot(mtcars, aes(factor(cyl))) + geom_bar()

Histogram

hist(mtcars$mpg, breaks = 10)

Histogram using ggplot2 (Quick Plot)

qplot(mpg, data = mtcars, binwidth = 5)

Histogram using ggplot2 (Robust Plot)

ggplot(mtcars, aes(mpg)) + geom_histogram(binwidth = 5)

BoxPlot

boxplot(mtcars$mpg)

Side-by-side Boxplot

boxplot(diamonds$x, diamonds$y, diamonds$z)

Colors in Barplot

barplot(BOD$demand, col = rainbow(6))

#barplot(BOD$demand, col = "royalblue3")

Colors for different scores

testscores <- c(96, 71, 85, 92, 82, 78, 72, 81, 68, 61, 78, 86, 90)
testcolors <- ifelse(testscores >= 80, "blue", "red")
barplot(testscores, col=testcolors, main="Test Scores", ylim = c(0,100), las=1)