Shiny Application Example

Developing Data Products - Course Project

Feng Qi
Coursera

Outline

  1. Shiny App example
  2. Iris dataset
  3. Interactive showing the plots and linear model fit for each species
  4. The model fit results shown in tables

Dataset

Load the Data Set

names(iris) = gsub("\\.", "", names(iris))

There 4 variables for each observation, total three species

head(iris)
##   SepalLength SepalWidth PetalLength PetalWidth Species
## 1         5.1        3.5         1.4        0.2  setosa
## 2         4.9        3.0         1.4        0.2  setosa
## 3         4.7        3.2         1.3        0.2  setosa
## 4         4.6        3.1         1.5        0.2  setosa
## 5         5.0        3.6         1.4        0.2  setosa
## 6         5.4        3.9         1.7        0.4  setosa

Plots

Select any two variables for each species, we plot the results

library(ggplot2)
names(iris) = gsub("\\.", "", names(iris))
ggplot(iris, aes(x=SepalLength, y=SepalWidth, color = Species)) + geom_point() +facet_grid(. ~ Species)

plot of chunk unnamed-chunk-3

Linear model fit

Simple linear fit for selected variables of each species: setosa, versicolor, and virginica.

summary(lm(SepalWidth~SepalLength,data=subset1))$coefficients
##             Estimate Std. Error t value  Pr(>|t|)
## (Intercept)  -0.5694     0.5217  -1.091 2.805e-01
## SepalLength   0.7985     0.1040   7.681 6.710e-10
##             Estimate Std. Error t value  Pr(>|t|)
## (Intercept)   0.8721    0.44466   1.961 5.565e-02
## SepalLength   0.3197    0.07463   4.284 8.772e-05
##             Estimate Std. Error t value  Pr(>|t|)
## (Intercept)   1.4463     0.4309   3.357 0.0015494
## SepalLength   0.2319     0.0651   3.562 0.0008435