CoCalc Shared FilesCDS-102 / Lab Week 06 - Data visualization with ggplot2 / CDS-102 Lab Week 06 Workbook.ipynb
Author: Nathaniel Sposit
Views : 19

# CDS-102: Lab 6 Workbook

## Name: Nathaniel Sposit

### March 2, 2017

In [1]:
# Run this code to install the GGally package (you only need to run this once)
install.packages("GGally", lib = "~/Rlibs")

In [2]:
# Run this code block to load the Tidyverse package
.libPaths(new = "~/Rlibs")
library(tidyverse)
library("GGally")

# This converts the iris data.frame to a tibble
iris <- as_tibble(iris)

In [3]:
print(iris)

# A tibble: 150 × 5 Sepal.Length Sepal.Width Petal.Length Petal.Width Species <dbl> <dbl> <dbl> <dbl> <fctr> 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 7 4.6 3.4 1.4 0.3 setosa 8 5.0 3.4 1.5 0.2 setosa 9 4.4 2.9 1.4 0.2 setosa 10 4.9 3.1 1.5 0.1 setosa # ... with 140 more rows
In [4]:
petal.width.length <- ggplot(data = iris) + geom_point(mapping = aes(Petal.Length, Petal.Width))
ggsave("PetalWidthLength.png", plot = petal.width.length, device = "png", scale = 1, width = 5, height = 4)
print(petal.width.length)

In [5]:
sepal.width.length <- ggplot(data = iris) + geom_point(mapping = aes(Sepal.Length, Sepal.Width))
ggsave("SepalWidthLength.png", plot = sepal.width.length, device = "png", scale = 1, width = 5, height = 4)
print(sepal.width.length)

In [6]:
petal.width.length.species <- ggplot(data = iris) + geom_point(mapping = aes(Petal.Length, Petal.Width, color = Species))
ggsave("PetalWidthLengthSpecies.png", plot = petal.width.length.species, device = "png", scale = 1, width = 5, height = 4)
print(petal.width.length.species)

In [7]:
sepal.width.length.species <- ggplot(data = iris) + geom_point(mapping = aes(Sepal.Length, Sepal.Width, color = Species))
ggsave("SepalWidthLengthSpecies.png", plot = sepal.width.length.species, device = "png", scale = 1, width = 5, height = 4)
print(sepal.width.length.species)

In [11]:
scatter.matrix <- ggpairs(data = iris, columns=1:4, upper = list(continuous = "points"), diag = NULL, mapping = aes(color=Species), legend = 3) + theme(legend.position = "right")
ggsave("ScatterplotMatrix.png", plot = scatter.matrix, device = "png", scale = 1, width = 5, height = 4)
print(scatter.matrix)

In [9]:
sepal.histo <- ggplot(iris, aes(Sepal.Length)) + geom_histogram(binwidth=5) + facet_wrap(~Species)
ggsave("SepalHisto.png", plot = sepal.histo, device = "png", scale = 1, width = 5, height = 4)
print(sepal.histo)

In [10]:
sepal.density <- ggplot(iris, aes(Sepal.Length)) + geom_density(kernel = "gaussian") + facet_wrap(~Species)
ggsave("SepalDensity.png", plot = sepal.density, device = "png", scale = 1, width = 5, height = 4)
print(sepal.density)

In [ ]: