5/27/2018

Overview

The purpose of the presentation is to perform exploratory data visualization.

This is done on the data in the Anorexia Dataset provided in the MASS library.

The data frame has 72 rows and 3 columns. It is a record of the weight change data for young female anorexia patients.

About the dataset

This data frame contains the following columns:

Treat: Factor of three levels.

      "Cont" (control),

      "CBT" (Cognitive Behavioural treatment) and

      "FT" (family treatment).

Prewt: Weight of patient before study period, in lbs.

Postwt: Weight of patient after study period, in lbs.

Preparing the data

# Load required libraries
library(MASS)
library(plotly)
library(tidyr)
library(dplyr)

# Load the data into variable 'ano'
data("anorexia")
ano = anorexia

# Create new variable Change which is the weight increased 
# of patients during the study period, in lbs
ano$Change = ano$Postwt - ano$Prewt

# Order the data according to weight before study started
# in ascending order
ano <- ano[order(ano$Prewt),]

Code for Plots

# Scatter plot between the weights before and after study for 
# different types of treatment
plot_ly(ano, x = ~Prewt, y = ~Postwt, color = ~Treat, 
        type = "scatter", mode="markers", opacity = 3)
# Box plot representing the Change in weight for different 
# types of treatment
plot_ly(ano, x = ~Change, color = ~Treat, type = "box")
# Bar plot representing the Weight before and after study 
# for each treatment
plot_ly(ano, x = ~Treat, y = ~Prewt, type = "bar", color = I("red"), 
        name="Prewt", opacity=0.5) %>%
  add_trace(y = ~Postwt, name = "Postwt", color=I("blue"), 
            opacity=0.5) %>%  
  layout(title="Weights Before and After Study", 
         yaxis=list(title="Count"))

Interactive Scatter Plot

Interactive Box Plot

Interactive Bar Plot