A Demo for the Github Distill page

In this demo I will be making some plots using the Iris data set – a boxplot and a scatter plot

Nathan Nguyen true
05-15-2021

Overview

This report will be a demo for the website that I am working on. This will just demonstrate my basic capabilities with the ggplot2 library by constructing a boxplot and a scatterplot with multiple linear models.

hide
getdata <- function(...){
  e = new.env()
  name = data(..., envir = e)[1]
  e[[name]]
}

data <- getdata("iris")

The boxplot

Sepal Length Boxplot by Species

hide
data %>%
  ggplot(aes(x = Species, y = Sepal.Length, fill = Species)) +
  geom_boxplot(aes(group = Species)) +
  labs(x = "Species",
       y = "Sepal Length",
       title = "Sepal Length Box Plot by Species") +
  theme(plot.title = element_text(hjust = 0.5),
        legend.position = "none") +
  scale_fill_d3()

The scatterplot and linear models by species

hide
data %>%
  ggplot(aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
  geom_point(aes(group = Species)) + geom_smooth(method = "lm", se = FALSE) +
  labs(x = "Sepal Length",
       y = "Sepal Width",
       title = "Sepal Width Function of Sepal Length") +
  scale_color_d3() +
  theme(plot.title = element_text(hjust = 0.5),
        legend.position = "top")

Stargazer Table

hide
stargazer(lm1, type = "html",
          covariate.labels = c("Versicolor", "Virginica", "Sepal Width"),
          dep.var.labels = "Sepal Length")
Dependent variable:
Sepal Length
Versicolor 1.459***
(0.112)
Virginica 1.947***
(0.100)
Sepal Width 0.804***
(0.106)
Constant 2.251***
(0.370)
Observations 150
R2 0.726
Adjusted R2 0.720
Residual Std. Error 0.438 (df = 146)
F Statistic 128.888*** (df = 3; 146)
Note: p<0.1; p<0.05; p<0.01