-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.R
215 lines (190 loc) · 9.16 KB
/
Main.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# List libraries
packages <- c("sp","raster","rlist","getSpatialData","sf","sp","list","leaflet","ggplot2","gganimate",
"ggmap","pals","ggdark","reshape2","RColorBrewer","plyr", "hms","stringi",
"shiny","shinyWidgets","shinythemes", "patchwork")
# import functions file
source("Functions.R")
# Load libraries
ipak(packages)
# Load data
LoadData(1)
###########################################################################################
#################################### GUI PLOTS ###########################################
########################################################################################### MAP
Map <- ggplot(Data, aes(x=LON, y=LAT, color=PPM))+
geom_point() +
geom_path(lineend = "round") +
coord_fixed(ratio = 1) +
scale_color_gradientn(colours = jet(100)) +
dark_theme_gray() +
labs(title = "GPS TEST",
subtitle = paste0("Date:", Data$DATE[1]),
x = "Longitude",
y = "Latitude",
color = "PPM") +
theme(plot.margin = unit(c(0.2,0.5,0.2,0.2), "cm"),
plot.background = element_rect(fill = "#282d32ff"),
panel.background = element_rect(fill = "#282d32ff"),
legend.background=element_blank())
Map
########################################################################################### BAROMETER
#Difine some constant values for the Alture plot
Graph_Y_Min <- round_any(min(Data$ALT_B),10)
Graph_Y_Max <- round_any(max(Data$ALT_B),5, f = ceiling)
Graph_X_Min <- 0
Graph_X_Max <- round_any(max(Data$ID),50, f = ceiling)
Base_Alture_Plot <- ggplot(Data, aes(x=ID,y=ALT_B)) +
geom_ribbon(aes(xmin=Graph_X_Min, xmax=Graph_X_Max,
ymin=Graph_Y_Min, ymax=pmax(ALT_B)),
fill="#606437ff", alpha=0.2) +
geom_line(color="#a8b063ff", alpha=0.6) +
coord_cartesian(xlim = c(min(Data$ID),Graph_X_Max),
ylim = c(Graph_Y_Min,Graph_Y_Max),
expand = FALSE) +
scale_x_continuous(breaks = seq(0, max(Data$ID), by = 50)) +
scale_y_continuous(breaks = seq(Graph_Y_Min, Graph_Y_Max, by=1)) +
geom_rect(xmin = max(Data$ID), xmax = Graph_X_Max, ymin = Graph_Y_Min, ymax = Graph_Y_Max, fill = "#282d32ff") +
geom_segment(aes(x=ID[ALT_B == max(ALT_B)],y= max(ALT_B), xend = length(Data$ID), yend = max(ALT_B)), linetype = 2, colour = 'grey') +
geom_text(aes(x = max(Data$ID), y = ALT_B[ALT_B == max(ALT_B)] , label = max(ALT_B)), hjust = -0.1) +
dark_theme_classic() +
theme(plot.margin = unit(c(0.2,0.5,0.2,0.2), "cm"),
plot.background = element_rect(fill = "#282d32ff"),
panel.background = element_rect(fill = "#282d32ff")) +
labs(title = "Altitude variations",
subtitle = "",
x = "Point ID",
y = "Recorded Atitude")
Base_Alture_Plot
########################################################################################### SPEED
Max_Y_Polar <- 1.168
Data$SPEED_p <- Data$SPEED * Max_Y_Polar / max(Data$SPEED)
Velocity_Plot <- ggplot(Data, aes(ymax = 2, ymin = 0, xmax = 2, xmin = 1, group = ID)) +
# Assign theme
dark_theme_classic() +
# Add background semicircle
annotate("rect", xmin=1, xmax=1.1, ymin=0, ymax=Max_Y_Polar, alpha=0.5, fill="#52524fff") +
# Add max vel semicircle
annotate("rect", xmin=1, xmax=1.1, ymin=1, ymax=Max_Y_Polar, alpha=0.8, fill="#5b1d1cff") +
# Add data semicircle
annotate("rect", xmin=1, xmax=1.1, ymin=0, ymax=Data$SPEED_p, alpha=0.9, fill="#c8c8c8ff") +
# Polar Y coordinate starting from -pi/2
coord_polar(theta = "y", start=-7*pi/12) + xlim(c(0, 2)) + ylim(c(0,2)) +
annotate(geom="text", x=0, y=1, label=Data$SPEED, color="#c8c8c8ff", size = 8) +
# Put text indicators
annotate(geom="text", x=0.6, y=0.59, label="SPEED", color="#c8c8c8ff", size = 6, alpha=0.8) +
# Put max min indicators
annotate(geom="text", x=1.3, y=0, label="0", color="#c8c8c8ff", size = 5, alpha=0.8) +
annotate(geom="text", x=1.35, y=Max_Y_Polar, label=round(max(Data$SPEED)), color="#c8c8c8ff", size = 5, alpha=0.8) +
# Polar Y coordinate starting from -pi/2
theme(line = element_blank(),
axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
plot.background = element_rect(fill = "#282d32ff"),
panel.background = element_rect(fill = "#282d32ff")) +
labs(title = "Speed", subtitle = "")
Velocity_Plot
########################################################################################### SPEED2
Max_Y_Polar <- 1.168
Data$SPEED_p <- Data$SPEED * Max_Y_Polar / max(Data$SPEED)
Velocity_Plot2 <- ggplot(Data, aes(ymax = 2, ymin = 0, xmax = 2, xmin = 1, group = ID)) +
# Assign theme
dark_theme_classic() +
# Add background semicircle
annotate("rect", xmin=1, xmax=1.1, ymin=0, ymax=Max_Y_Polar, alpha=0.5, fill="#52524fff") +
# Add max vel semicircle
annotate("rect", xmin=1, xmax=1.1, ymin=1, ymax=Max_Y_Polar, alpha=0.8, fill="#5b1d1cff") +
# Add data semicircle
annotate("rect", xmin=1, xmax=1.1, ymin=0, ymax=Data$SPEED_p[100], alpha=0.9, fill="#c8c8c8ff") +
# Polar Y coordinate starting from -pi/2
coord_polar(theta = "y", start=-7*pi/12) + xlim(c(0, 2)) + ylim(c(0,2)) +
annotate(geom="text", x=0, y=1, label=Data$SPEED, color="#c8c8c8ff", size = 8) +
# Put text indicators
annotate(geom="text", x=0.6, y=0.59, label="SPEED", color="#c8c8c8ff", size = 6, alpha=0.8) +
# Put max min indicators
annotate(geom="text", x=1.3, y=0, label="0", color="#c8c8c8ff", size = 5, alpha=0.8) +
annotate(geom="text", x=1.35, y=Max_Y_Polar, label=round(max(Data$SPEED)), color="#c8c8c8ff", size = 5, alpha=0.8) +
# Polar Y coordinate starting from -pi/2
theme(line = element_blank(),
axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
plot.background = element_rect(fill = "#282d32ff"),
panel.background = element_rect(fill = "#282d32ff")) +
labs(title = "Speed", subtitle = "")
Velocity_Plot2
###########################################################################################
# Gif <- Velocity_Plot + transition_states(Data$ID) +
# ease_aes('linear') +
# enter_fade() +
# exit_fade()
# animate(Gif, fps = 10, width = 500, height = 500)
###########################################################################################
leaflet(Data) %>% addTiles() %>% addPolylines(~LON, ~LAT)
Patch <- (Map)/(Base_Alture_Plot|Velocity_Plot|Velocity_Plot2) + plot_layout(ncol=1, heights=c(1,0.20))
Patch + plot_annotation(title = "Bike DataLog",
subtitle = "Version 1.0",
caption = "Schientific Graphics - JMU")
###########################################################################################
####################################### IDEAS ############################################
###########################################################################################
# use and mod the https://movevis.org/ package to plot raster characteristics from the GPS TRACKS
# transform Fusion2020 into package to aquire S1&S2$S5 images from the GPS TRACK automatically
#https://cran.r-project.org/web/packages/pals/vignettes/pals_examples.html
######################## PLOT DATA
# Plot <- ggplot(Data, aes(x=LON, y=LAT, color=ALT_B))+
# geom_point() +
# geom_path(lineend = "round") +
# coord_fixed(ratio = 1) +
# scale_color_gradientn(colours = jet(100)) +
# dark_theme_gray() +
# labs(title = "GPS TEST",
# subtitle = paste0("Date:", Data$DATE[1]),
# x = "Longitude",
# y = "Latitude",
# color = "Height m")
#
# Plot
# ######################## MAKE GIF
# Gif <- Plot + transition_reveal(along = ID)
# animate(Gif, fps = 10, width = 694, height = 403)
# anim_save("Test.gif")
#
# ######################## PLOT DENSITY TO CHECK SLOW POINTS
# ggplot(Data, aes(x=LON, y=LAT) ) +
# geom_bin2d(bins = 200) +
# dark_theme_gray() +
# scale_fill_continuous(type = "viridis") +
# labs(title = "GPS DENSITY",
# subtitle = "Date: 17/05/20",
# x = "Longitude",
# y = "Latitude",
# color = "Bins")
#
# ######################## PLOT DENSITY 2 TO CHECK SLOW POINTS
# ggplot(Data, aes(x=LON, y=LAT) ) +
# stat_density_2d(aes(fill = ..density..), geom = "raster", contour = FALSE) +
# scale_fill_distiller(palette= "RdYlBu") +
# scale_x_continuous(expand = c(0, 0)) +
# scale_y_continuous(expand = c(0, 0)) +
# dark_theme_gray() +
# geom_path(lineend = "round", color="Black") +
# labs(title = "GPS DENSITY",
# subtitle = "Date: 17/05/20",
# x = "Longitude",
# y = "Latitude",
# color = "Bins")
#
#
# ############################### map it ###########################################
leaflet(Data) %>% addTiles() %>% addPolylines(~LON, ~LAT)
# ######################## EXPORT GEOPACKAGE##########################
# p.sf <- st_as_sf(Data, coords = c("LON", "LAT"), crs = 4326)
# st_write(p.sf, "Points_test.gpkg", driver="GPKG") # Create a geopackage file
anim_save("filename.gif", animation = last_animation())