-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplot.replicates.R
149 lines (135 loc) · 6.34 KB
/
plot.replicates.R
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
insert_minor <- function(major_labs, n_minor){
#function to create minor ticks
labs <- c(sapply(major_labs, function(x) c(x, rep("", 4))))
labs[1:(length(labs) - n_minor)]
}
plot.replicates <- function(my_data)
{
#function to plot gray replicates and the mean in black
g <- ggplot(my_data, aes(x = Wavelength, y = Reflectance)) +
geom_line(aes(group=Replicate),size=0.2,colour="gray62") +
stat_summary(fun.y = "mean", colour = "black", size = 1, geom = "line")+
scale_x_continuous(breaks = seq(325, 1080, by = 30),
labels = insert_minor(seq(325, 1080, by=150), 4),
limits = c(325, 1080), expand = c(0, 0)) +
scale_y_continuous(expand = c(0, -0.05), limits = c(-0.05, 1.05))+ #Set max 1
theme(axis.text=element_text(size=12),
axis.title=element_text(size=14,face="bold"))+
xlab("Wavelength (nm)") + ylab("Reflectance") +
background_grid(major = "none", minor = "none")
return(g)
}
plot.bydates <- function(my_data)
{
#function to plot replicates grouped by date
d <-ggplot(my_data, aes(x = Wavelength, y = Reflectance, colour=Date)) +
geom_line(size=0.2) +
scale_x_continuous(breaks = seq(325, 1080, by = 30),
labels = insert_minor(seq(325, 1080, by=150), 4),
limits = c(325, 1080), expand = c(0, 0)) +
scale_y_continuous(expand = c(0, -0.05), limits = c(-0.05, 1.05))+ #Set max 1
theme(axis.text=element_text(size=12),
axis.title=element_text(size=14,face="bold"))+
guides(colour = guide_legend(override.aes = list(size=5)))+
xlab("Wavelength (nm)") + ylab("Reflectance") +
background_grid(major = "none", minor = "none")
return(d)
}
plot.byLC<-function(my_data)
{
#Function to plot replicates grouped by light conditions
l<-ggplot(my_data, aes(x = Wavelength, y = Reflectance, colour=Light)) +
geom_line(size=0.2) +
scale_x_continuous(breaks = seq(325, 1080, by = 30),
labels = insert_minor(seq(325, 1080, by=150), 4),
limits = c(325, 1080), expand = c(0, 0)) +
scale_y_continuous(expand = c(0, -0.05), limits = c(-0.05, 1.05))+ #Set max 1
scale_color_manual(
values = c(
"Clear sky"="#00e6e6",
"Cloudy"="#4d4dff",
"Overcast"="#636363"))+
theme(legend.title = element_blank(),
axis.text=element_text(size=12),
axis.title=element_text(size=14,face="bold"))+
guides(colour = guide_legend(override.aes = list(size=3)))+
xlab("Wavelength (nm)") + ylab("Reflectance") +
background_grid(major = "none", minor = "none")
return(l)
}
plot.byrep <- function(my_data)
{#Function to plot replicates on different colours
g <- ggplot(my_data, aes(x = Wavelength, y = Reflectance, colour= Replicate)) +
geom_line(size=0.2) +
stat_summary(fun.y = "mean", colour = "black", size = 1, geom = "line")+
scale_x_continuous(breaks = seq(325, 1080, by = 30),
labels = insert_minor(seq(325, 1080, by=150), 4),
limits = c(325, 1080), expand = c(0, 0)) +
scale_y_continuous(expand = c(0, -0.05), limits = c(-0.05, 1.05))+ #Set max 1
theme(axis.text=element_text(size=12),
axis.title=element_text(size=14, face="bold"))+
guides(colour = guide_legend(override.aes = list(size=5)))+
xlab("Wavelength (nm)") + ylab("Reflectance") +
background_grid(major = "none", minor = "none")
return(g)
}
plot.repR <- function(my_data)
{
#function to plot gray replicates and the mean in black (Micasense range)
g <- ggplot(my_data, aes(x = Wavelength, y = Reflectance)) +
geom_line(aes(group=Replicate),size=0.2,colour="gray62") +
stat_summary(fun.y = "mean", colour = "black", size = 1, geom = "line")+
scale_x_continuous(breaks = seq(465, 865, by = 20),
labels = insert_minor(seq(465, 865, by=100), 4),
limits = c(465, 865), expand = c(0, 0)) +
scale_y_continuous(breaks = seq(0, 1, by = 0.1), expand = c(0, -0.05), limits = c(-0.05, 1.05))+ #Set max 1
theme(axis.text=element_text(size=12),
axis.title=element_text(size=14,face="bold"))+
xlab("Wavelength (nm)") + ylab("Reflectance") +
background_grid(major = "none", minor = "none")
return(g)
}
plot.grayS<-function(my_data)
{
#Function to plot lines on gray scale (lower values darker)
g<-ggplot(my_data, aes(x=Wavelength, y=Reflectance, colour=Target)) +
geom_line(size=0.8)+
scale_colour_grey(name="")+
scale_x_continuous(breaks= seq(325,1080,by=30),
labels = insert_minor(seq(325, 1080, by=150),4),
limits = c(325,1080), expand =c(0,0)) +
scale_y_continuous(expand =c(0,-0.05), limits= c(-0.05, 1.05))+ #Set max 1
theme(axis.text=element_text(size=12),
axis.title=element_text(size=14,face="bold"))+
xlab("Wavelength (nm)") + ylab("Reflectance") +
background_grid(major = "none", minor = "none")
return(g)
}
plot.graySM<-function(my_data)
{
#Function to plot lines on gray scale (Micasense Range)
g<-ggplot(my_data, aes(x=Wavelength, y=Reflectance, colour=Target)) +
geom_line(size=0.8)+
scale_colour_grey(name="")+
scale_x_continuous(breaks = seq(465, 865, by = 20),
labels = insert_minor(seq(465, 865, by=100), 4),
limits = c(465, 865), expand = c(0, 0)) +
scale_y_continuous(expand =c(0,-0.05), limits= c(-0.05, 1.05))+ #Set max 1
theme(axis.text=element_text(size=12),
axis.title=element_text(size=14,face="bold"))+
xlab("Wavelength (nm)") + ylab("Reflectance") +
background_grid(major = "none", minor = "none")
return(g)
}
plot.irrad<-function(my_data)
{
#Function to plot irradiance replicates on different colours
g<-ggplot(my_data, aes(x = Wavelength, y = Irradiance, colour=Time)) +
geom_line(size=0.8)+
scale_y_continuous(expand = c(0, -0.05), limits = c(-0.05, 1.2))+
theme(axis.text=element_text(size=12),
axis.title=element_text(size=14,face="bold"))+
xlab("Wavelength (nm)") + ylab("Irradiance (W/m2/nm)") +
background_grid(major = "none", minor = "none")
return(g)
}