Q1

A

x1 <- rnorm(100, mean = 100, sd = 10)
y1 <- x1 + rnorm(100, mean = 20, sd = 20)

B

Create a histogram for variable x

hist(x = x1)

C

Create a histogram for variable y

hist(x = y1)

D

Create a scatterplot with x on the x-axis and y on the y-axis.

plot(x=x1, y=y1)

E

Using the abline() function, add a (dashed) horizontal and vertical line at the mean of each variable.

plot(x=x1, y=y1)
abline(h=mean(y1))
abline(v=100)

Q2

colors()[1:10]
##  [1] "white"         "aliceblue"     "antiquewhite"  "antiquewhite1"
##  [5] "antiquewhite2" "antiquewhite3" "antiquewhite4" "aquamarine"   
##  [9] "aquamarine1"   "aquamarine2"
sample(x = 1:100,  size = 10)
##  [1] 23 45 70  5 41  9 59 30 69 32
samp.numbers <- sample(1:657, size = 10)
colors.to.use <- colors()[samp.numbers]

plot(1:10, 
     col = colors.to.use,
     pch = 8,
     cex = 3,
     xlim = c(0, 11),
     ylim = c(0, 11)
     )

text(1:10, 
     1:10, 
     colors()[samp.numbers],
     pos = 3
     )

Q3

require("RColorBrewer")
## Loading required package: RColorBrewer
bean.cols <- lapply(brewer.pal(6, "Set3"),
function(x) {return(c(x, "black", "black", "black"))})

colors4 <- c("yellow", "blue", "red", "green")

boxplot(pirates$sword.speed~pirates$sword.type,
         what = c(1,1,1,0),
         xlab = "Sword Type",
         ylab = "Swing Time",
         main = "Beanplot",
         col = colors4,
         ylim = c(0,11))