forked from bioinformatics-core-shared-training/basicr
-
Notifications
You must be signed in to change notification settings - Fork 40
/
solution-exercise5.Rmd
78 lines (65 loc) · 2.03 KB
/
solution-exercise5.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
---
title: "Exercise 5"
author: "Your Name"
date: '`r format(Sys.time(), "%d %b %Y")`'
output: pdf_document
---
```{r}
weather <- read.csv("ozone.csv")
```
+ Plot Ozone versus Solar Radiation, Wind Speed and Temperature on separate graphs
- save the plot to a pdf file
```{r}
pdf("ozoneCorrelations.pdf")
par(mfrow=c(1,3))
plot(weather$Solar.R, weather$Ozone, pch=16,
col="lightgreen", ylab="Ozone level",
xlab="Solar Radiation")
plot(weather$Wind, weather$Ozone, pch=15,
col="steelblue", ylab="Ozone level",
xlab="Wind Speed")
plot(weather$Temp,weather$Ozone, pch=17,
col="orange", ylab="Ozone level",
xlab="Temperature")
dev.off()
```
+ Repeat the plot of Ozone versus Temperature and use a different colour to highlight any points with Ozone level > 100
```{r}
highO <- which(weather$Ozone > 100)
lowO <- which(weather$Ozone < 100)
plot(weather$Temp,weather$Ozone, type="n",
ylab="Ozone level",
xlab="Temperature")
points(weather$Temp[highO],weather$Ozone[highO],
col="red",pch=17)
points(weather$Temp[lowO],weather$Ozone[lowO],
col="orange",pch=17)
abline(h=100,lty=2)
legend("topleft", legend = c("Ozone > 100","Normal Ozone"),col=c("red","orange"),pch=17)
```
```{r}
mycol <-rep("orange",nrow(weather))
highO <- which(weather$Ozone > 100)
mycol[highO] <- "red"
mypch <- rep(17, nrow(weather))
mypch[highO] <- 18
plot(weather$Temp,weather$Ozone,
col=mycol, pch=mypch,ylab="Ozone level",
xlab="Temperature")
abline(h=100,lty=2)
legend("topleft", legend = c("Ozone > 100","Normal Ozone"),col=c("red","orange"),pch=17)
```
Defining a variable for the cut-off makes our code a bit more flexible
```{r}
mycol <-rep("orange",nrow(weather))
cutoff <- 100
highO <- which(weather$Ozone > cutoff)
mycol[highO] <- "red"
mypch <- rep(17, nrow(weather))
mypch[highO] <- 18
plot(weather$Temp,weather$Ozone,
col=mycol, pch=mypch,ylab="Ozone level",
xlab="Temperature")
abline(h=cutoff,lty=2)
legend("topleft", legend = c("Ozone > 100","Normal Ozone"),col=c("red","orange"),pch=17)
```