Visualizing Data

Sameer Mathur

Reading, Processing and Describing ISLR Data

Using data.table()

---

VISUALIZING DATA

Importing Data

library(ISLR)
library(data.table)
# reading inbuilt data as data table
default.dt <- data.table(Default)
# reading inbuilt data as data frame
default.df <- as.data.frame(default.dt)

VISUALIZATION: CATEGORICAL VARIABLES

Boxplot of Income by Deafulters

# boxplot of income by defaulters
boxplot(income ~ default, data = default.dt,
        main = "Boxplot of Income by Defaulters",
        xlab = "Defaulters", ylab = "Income (USD)",
        col = c("grey", "light blue"))

plot of chunk unnamed-chunk-3

Boxplot of Income by Deafulters and Student

# boxplot of income by defaulters
boxplot(income ~ default * student, data = default.dt,
        main = "Boxplot of Income by Defaulters",
        xlab = "Defaulters | Student", ylab = "Income (USD)",
        col = c("grey", "light blue"))

plot of chunk unnamed-chunk-5

ALTERNATE

library(lattice)# boxplot of income by defaulters
bwplot(income ~ default | student, data = default.dt, 
       horizontal = FALSE, xlab = "Defaulters")

plot of chunk unnamed-chunk-7

Mean Plot of Income by Deafulters

# mean plot of income by defaulters
library(gplots)
plotmeans(income ~ default, data = default.dt,
          xlab = "Defaulters", ylab = "Income (USD)",
          frame = TRUE, mean.labels = TRUE)

plot of chunk unnamed-chunk-9

Mean Plot of Balance by Deafulters

# mean plot of balance by defaulters
library(gplots)
plotmeans(balance ~ default, data = default.dt,
          xlab = "Defaulters", ylab = "Balance (USD)",
          frame = TRUE, mean.labels = TRUE)

plot of chunk unnamed-chunk-11

VISUALIZATION: CONTINUOUS VARIABLES

Scatter Plot of Income and Balance by Defaulters

# scatter plot of income and balance by defaulters
xyplot(balance ~ income, group = default, data = default.dt,
       ylab = "Balance (USD)", xlab = "Income (USD)",
       main = "Scatter Plot of Income and Balance by Defaulters")

plot of chunk unnamed-chunk-13

ALTERNATE: Scatter Plot of Income and Balance by Defaulters

# scatter plot of income and balance by defaulters
xyplot(balance ~ income | default, data = default.dt,
       ylab = "Balance (USD)", xlab = "Income (USD)",
       main = "Scatter Plot of Income and Balance by Defaulters",
       type = c("p", "smooth"), scales = "free")

plot of chunk unnamed-chunk-15