knitr::opts_chunk$set(echo = TRUE)

Task 1

getwd()

Task 2

ddt = read.csv("DDT.csv")
head(ddt)

Task 3

Some questions

  1. Qualitative variables are RIVER and SPECIES.
  2. Quantitative variables are MILE, LENGTH, WEIGHT, DDT.
  3. Using length(unique(ddt$SPECIES)) I found 3 unique species.
  4. Subset showing only LMBASS > 800gms (directly below).
subset(ddt, ddt$SPECIES == "LMBASS" & ddt$WEIGHT > 800)
  1. Subset showing only RIVER SCM and DDT > 4.0 (directly below).
subset(ddt, ddt$RIVER == "SCM" & ddt$DDT > 4.0)

Clicker questions

  1. Mean length found with mean(ddt$LENGTH) or summary(ddt) and is 42.81
  2. Standard deviation of the weight of fish is 376.5461
  3. No. Although the axes are correct, the data is inverse.
  4. The last value of v / 20 is 1.00

Task 4

Table of rivers

table(ddt$RIVER)

Color-coded barplot of rivers

barplot(with(ddt,table(RIVER)),col=1:4, xlab = "Rivers", ylab = "# of ish measured")

Table of rivers x species

data <- with(ddt,table(RIVER, SPECIES))
data

Barplot of rivers x species

data <- with(ddt,table(RIVER, SPECIES))
barplot(data,ylim = c(0, 100), col=1:4,beside = T, legend.text = c("FCM", "LCM", "SCM", "TRM"), xlab = "Species", ylab = "# of fish measured", args.legend = list(x="topleft",title="Rivers") )

Task 5

Pie chart of species

species <- with(ddt, table(SPECIES))
pie(species,col = 1:3,main = "Species distribution")

Pie chart of rivers

rivers <- with(ddt, table(RIVER))
  pie(rivers,col = 1:4,main = "Distribution of rivers where fish were measured")

Task 6

Make boxplots of DDT, WEIGHT, LENGTH

layout(matrix(c(1,2,3),nr=1,nc=3))# 1 row 3 cols
with(ddt,boxplot(LENGTH,ylab="LENGTH",col="Blue",notch=TRUE))
with(ddt,boxplot(WEIGHT,ylab="WEIGHT",col="Green",notch=TRUE))
with(ddt,boxplot(DDT,ylab="DDT",col="Red",notch=TRUE))

Task 7

Coplot of LENGTH vs WEIGHT given RIVER

Note: The instructions say LENGTH vs WEIGHT, so I've put Length on the Y-axis and Weight on the X-axis as I've been trained by previous math courses.

coplot(LENGTH~WEIGHT|RIVER,data=ddt)

Coplot of DDT vs WEIGHT given SPECIES

coplot(DDT~WEIGHT|SPECIES,data=ddt)

Task 8

Barplot

library(ggplot2)
p <- ggplot(ddt, aes(x=SPECIES, y=WEIGHT, fill=RIVER)) + 
  geom_boxplot() + ggtitle(label = "Adam Gracy")
p

Violin plot

library(ggplot2)
p <- ggplot(ddt, aes(x=RIVER, y=LENGTH, fill = SPECIES)) + 
  geom_violin() + ggtitle("Adam Gracy")
p

Scatter plot

library(ggplot2)

p <- ggplot(ddt,aes(x=WEIGHT, y= LENGTH, color=SPECIES)) + geom_point() + ggtitle("Adam Gracy")
p


agracy2246/MATH4753grac0009 documentation built on April 26, 2020, 9:39 a.m.