#Title: DWV Assignment 4 Solutions.R
#Author: Jack Reilly
#Purpose: Solve Assignment 4
#Requires: 
#Output: Plots to plot window; nothing to disk

#Assignment 4
library(tidyverse)
setwd("~/desktop/working/dwv/")

#Part I. Lines

#Draw a y=4x+3 on a plot that ranges from -20 to +20 on both x and y.
#Label the line appropriately next to itself.
#Color the line in an interesting color! And make it dashed.
plot(x=0, 
     type='n', 
     xlim=c(-20,20), 
     ylim=c(-20,20),
     xlab="This is the X axis", 
     ylab="This is the Y axis", 
     main="My Line")

abline(h=0, v=0, col = "gray")

abline(a=3, 
       b=4, 
       col = "forestgreen", 
       lwd=3, 
       lty = "dashed")

text(5,12, "y=4x+3", col = "forestgreen")

#Bonus: Use a combination of the above options (plus others, if you feel like looking them up) to create the wildest looking series of lines on a graph that you can. (Remember, you can overplot lines!)

#Here's some lines
plot(x=0, type='n', xlim=c(-10,10), ylim=c(-10,10), xlab="x", ylab="y", main="Drawing Some Lines")
abline(h=0, v=0, col = "gray")

abline(a=0, b=1, col = "purple", lwd=110)
abline(a=0, b=-1, col = "purple", lwd=110)

abline(a=0, b=1, col = "blue", lwd=100)
abline(a=0, b=-1, col = "blue", lwd=100)

abline(a=0, b=1, col = "green", lwd=90)
abline(a=0, b=-1, col = "green", lwd=90)

abline(a=0, b=1, col = "yellow", lwd=80)
abline(a=0, b=-1, col = "yellow", lwd=80)

abline(a=0, b=1, col = "orange", lwd=70)
abline(a=0, b=-1, col = "orange", lwd=70)

abline(a=0, b=1, col = "red", lwd=60)
abline(a=0, b=-1, col = "red", lwd=60)

abline(a=0, b=1, col = "white", lwd=50)
abline(a=0, b=-1, col = "white", lwd=50)

abline(a=0, b=1, col = "orange", lwd=50)
abline(a=0, b=-1, col = "orange", lwd=50)

abline(a=0, b=1, col = "yellow", lwd=40)
abline(a=0, b=-1, col = "yellow", lwd=40)

abline(a=0, b=1, col = "green", lwd=30)
abline(a=0, b=-1, col = "green", lwd=30)

abline(a=0, b=1, col = "blue", lwd=20)
abline(a=0, b=-1, col = "blue", lwd=20)

abline(a=0, b=1, col = "purple", lwd=10)
abline(a=0, b=-1, col = "purple", lwd=10)

abline(a=0, b=1, col = "black", lwd=5, lty="dotted")
abline(a=0, b=-1, col = "black", lwd=5, lty="dotted")

#Part 2. Protected Lands

lands<-read_csv("datasets/protected_lands.csv")

mean(lands$protected_lands)
mean(lands$gdp_percap)
mean(lands$tot_gdp_bilions)

sd(lands$protected_lands)
sd(lands$gdp_percap)
sd(lands$tot_gdp_bilions)

range(lands$protected_lands)
range(lands$gdp_percap)
range(lands$tot_gdp_bilions)

plot(x=0, type='n', xlim=c(0,12000), ylim=c(0,50), xlab="Total GDP", ylab="Protected Lands", main="Protected Lands by Country GDP")
points(y=lands$protected_lands, x=lands$tot_gdp_bilions, pch=20)

model_tot<-lm(lands$protected_lands~lands$tot_gdp_bilions)

abline(model_tot, col="red", lwd=2)

plot(x=0, type='n', xlim=c(3000,60000), ylim=c(0,50), xlab="GDP Per Capita", ylab="Protected Lands", main="Protected Lands by Country GDP Per Capita")
points(y=lands$protected_lands, x=lands$gdp_percap, pch=20)

model_pc<-lm(lands$protected_lands~lands$gdp_percap)

abline(model_pc, col="red", lwd=2)





