-
Notifications
You must be signed in to change notification settings - Fork 5
/
hw3solutions.Rmd
97 lines (80 loc) · 2.53 KB
/
hw3solutions.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
title: 'Homework 3: Solutions'
author: "Amy Allen & Dayne Filer"
date: "June 28, 2016"
output:
pdf_document:
highlight: tango
html_document: null
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, collapse = TRUE)
```
<!-- Here we style out button a little bit -->
<style>
.showopt {
background-color: #004c93;
color: #FFFFFF;
width: 100px;
height: 20px;
text-align: center;
vertical-align: middle !important;
border-radius: 8px;
float:right;
}
.showopt:hover {
background-color: #dfe4f2;
color: #004c93;
}
</style>
<!--Include script for hiding output chunks-->
<script src="hideOutput.js"></script>
Load data:
```{r}
setwd("~/Documents/rclass")
data <- read.csv("heights.csv", header = TRUE)
```
1. Make a histogram of height using the `hist()` function. Include an appropriate title and axis labels.
```{r}
hist(x = data$Height,
xlab = "Height (inches)",
ylab = "Frequency",
main = "Histogram of Height")
```
\pagebreak
2. Now make the same histogram but include 20 bins and make it your favorite color.
```{r}
hist(x = data$Height,
xlab = "Height (inches)",
ylab = "Frequency",
main = "Histogram of Height",
breaks = 20,
col = "purple")
```
\pagebreak
3. Make a bar chart of how many people are left or right handed using the `barplot()` function. Hint: `data$Handedness[data$Handedness=="Left"]` will return a vector including on those entries where `data$Handedness` is `"Left"` and `length()` will return the length of a vector.
```{r}
barplot(height = c(length(data$Handedness[data$Handedness =="Left"]),
length(data$Handedness[data$Handedness =="Right"])),
names.arg = c("Left Handed","Right Handed"),
ylab = "Count",
main = "Handedness")
```
\pagebreak
4. Make a bar chart of how many people have the following eye colors: blue, brown, other. Make the color of each bar correspond to the eye color (you can choose any color for other).
```{r}
barplot(height = c(length(data$Eye.Color[data$Eye.Color == "Blue"]),
length(data$Eye.Color[data$Eye.Color == "Brown"]),
length(data$Eye.Color[data$Eye.Color == "Other"])),
names.arg = c("Blue","Brown","Other"),
ylab = "Count",
main = "Eye Color",
col = c("blue","brown","purple"))
```
\pagebreak
5. Make a box plot of the height using the `boxplot()` function.
```{r}
boxplot(x = data$Height,
ylab = "Height (inches)",
main = "Boxplot of Height")
```