-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
512 lines (512 loc) · 23.5 KB
/
.Rhistory
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
lat = c(25, 53, 49),
popup = popup)
library(leaflet)
popup = c("Bijesh", "Rajesh", "Shyam")
leaflet() %>%
addProviderTiles("NASAGIBS.ViirsEarthAtNight2012") %>%
addMarkers(lng = c(85, 23, 11),
lat = c(25, 53, 49),
popup = popup)
library(leaflet)
popup = c("Bijesh", "Rajesh", "Shyam")
leaflet() %>%
addProviderTiles("NASAGIBS.ViirsEarthAtNight2012") %>%
addMarkers(lng = c(80, 23, 11),
lat = c(25, 53, 49),
popup = popup)
library(leaflet)
popup = c("Bijesh", "Rajesh", "Shyam")
leaflet() %>%
addProviderTiles("NASAGIBS.ViirsEarthAtNight2012") %>%
addMarkers(lng = c(80, 23, 11),
lat = c(22, 53, 49),
popup = popup)
library(leaflet)
popup = c("Bijesh", "Rajesh", "Shyam")
leaflet() %>%
addProviderTiles("NASAGIBS.ViirsEarthAtNight2012") %>%
addMarkers(lng = c(80, 23, 11),
lat = c(28, 53, 49),
popup = popup)
library(leaflet)
popup = c("Bijesh", "Rajesh", "Shyam")
leaflet() %>%
addProviderTiles("NASAGIBS.ViirsEarthAtNight2012") %>%
addMarkers(lng = c(80, 23, 11),
lat = c(30, 53, 49),
popup = popup)
library(leaflet)
popup = c("Bijesh", "Rajesh", "Shyam")
leaflet() %>%
addProviderTiles("NASAGIBS.ViirsEarthAtNight2012") %>%
addMarkers(lng = c(85, 23, 11),
lat = c(30, 53, 49),
popup = popup)
library(leaflet)
popup = c("Bijesh", "Rajesh", "Shyam")
leaflet() %>%
addProviderTiles("NASAGIBS.ViirsEarthAtNight2012") %>%
addMarkers(lng = c(82, 23, 11),
lat = c(30, 53, 49),
popup = popup)
library(leaflet)
popup = c("Bijesh", "Rajesh", "Shyam")
leaflet() %>%
addProviderTiles("NASAGIBS.ViirsEarthAtNight2012") %>%
addMarkers(lng = c(83, 23, 11),
lat = c(30, 53, 49),
popup = popup)
library(leaflet)
popup = c("Bijesh", "Rajesh", "Shyam")
leaflet() %>%
addProviderTiles("NASAGIBS.ViirsEarthAtNight2012") %>%
addMarkers(lng = c(-3, 23, 11),
lat = c(52, 53, 49),
popup = popup)
source('~/Documents/GitHub/GeoComputationWithR/R/GeoComputation.R')
#current system time
Sys.time()
# current system timezone:
Sys.chmod()
# current system timezone:
Sys.timezone()
# Changed time zone to
Sys.setenv( TZ = Kathmandu/Nepal)
# Changed time zone to
Sys.setenv( TZ = "Kathmandu")
Sys.time()
Sys.timezone()
Sys.time()
Sys.timezone()
# current system timezone:
Sys.timezone()
Sys.timezone()
Sys.time()
source('~/Documents/GitHub/GeoComputationWithR/R/GeoComputation.R')
example
example("tidyverse")
max.plot = 14
summary(world["lifeExp"])
world_mini = world[1:2, 1:3]
world_mini
View(world)
View(world_mini)
View(world_mini)
View(world)
world_sp = as(world, Class = "Spatial")
# Set working directory:
setwd("~/Documents/GitHub/GeoComputationWithR")
# ##### Contribute (Not Necesssary for Class) #####
# devtools::install_github("geocompr/geocompkg") #Reporduce code in the book.
# library(bookdown)
# bookdown::render_book("index.Rmd") # to build the book locally.
# browseURL("_book/index.html") # to view it.
# ##### Homework 1: Chapter 1 (Already completed ; No Need to open) #####
# Introduction
# 1.1 What is geocomputation?: Closely related to Geographic Information science, geomatics, geoinformatics, spatial information science, geoinfomatiion engineering and geographical data science (GDS).
# 1.2 Why use R for geocomputation?
# install.packages("leaflet")
library(leaflet)
popup = c("Bijesh", "Rajesh", "Shyam") # I changed author's name. Sorry!!!
leaflet() %>%
addProviderTiles("NASAGIBS.ViirsEarthAtNight2012") %>%
addMarkers(lng = c(-3, 23, 11),
lat = c(52, 53, 49),
popup = popup)
# 1.3 Software for geocomputation: QGIS, GRASS and SAGA built on C++, C++ is fasst but hard to learn compared to python. Rcpp made C++ more accessible. Java is another important program.Python is important program for geocomputing. Packages: osgeo, Shapely, NumPy, PyGeoProcessing.
# 1.4 R’s spatial ecosystem
# 1.5 The history of R-spatial
# 1.6 Exercises
# Q1. Think about the terms "GIS" and "geocomputation" described above. Which (if any) best describe the work you would like to do using geo* methods and software and why?
# Q2. Provide three reasons for using a scriptable language such as R for geocomputation instead of using an established GIS program such as QGIS?
# Q3. Name two advantages and two disadvantages of using mature vs recent packages for geographic data analysis (for example sf vs sp).
# Note: Python modules providing access to geoalgorithms include grass.script for GRASS, saga-python for SAGA-GIS, processing for QGIS and arcpy for ArcGIS.
# An overview of R’s spatial ecosystem can be found in the CRAN Task View on the Analysis of Spatial Data (see https://cran.r-project.org/web/views/Spatial.html).↩
# ##### Chapter 2: Geographic Data in R #####
# # Prerequisites:
# # Install Packages:
# # this step is to install library from github:
# install.packages("devtools") #install devtools package. Do not run of devtools is alread present in your machine.
# library(devtools) #load devtools before downloading packages from github.
# install_github("r-spatial/sf") #isntall sf package from github
# devtools::install_github("r-spatial/sf", type = "binary", force = TRUE) #This works without attaching devtools library.
# install.packages("raster")
# install.packages("spData")
# install.packages("devtools") #Install this package if you are installing packages from GitHub.
# devtools::install_github("Nowosad/spDataLarge", force = TRUE) #Need to add "Force = TRUE" to install this package in my MAC.
# install.packages("sf", type = "binary") #OSU IT People response: There is no such non-binary version. Homebrew and gdal packages are only necessary if you want to modify package. For, user, binary version is enough.
# Load Libraries.
library(raster) #class ad function for raster data.
library(spData) #load geographic data.
library(devtools) #used to install packages from GitHub.
library(spDataLarge) #Load larger geograpic Data.
library(sf) #class and function for vector data
# 2.2.1 An introduction to simple features:
vignette(package = "sf") # see which vignettes/descriptions are available
vignette("sf1") # an introduction to the package
names(world) #world is spatial object containing spatial and attribute columns returned by this function.
plot(world) #plot world.
summary(world["lifeExp"]) # geom is stick with the desired variable unless it is removed. MULTIPOLYGON is seen for countries with Island.
world_mini = world[1:2, 1:3] #A subset of first two row (from row 1 to rown 2) and three columns (from column 1 to column 3). This adds additional geographical data (geometry type, dimension, bbox) and CRS information ( epsg(SRID), proj4string ) and the presence of a geometry column (geom).
world_mini
View(world)
# 2.2.2 Why simple features (sf)? #Advantage: Cross transferrable.Also supports %>%, tmap, mapview, tidycensus.
library(sp)
world_sp = as(world, Class = "Spatial")
world_sf = st_as_sf(world_sp)
# 2.2.3 Basic map making
plot(world[3:6])
plot(world["pop"])
world_asia = world[world$continent == "Asia", ]
asia = st_union(world_asia)
plot(world["pop"], reset = FALSE)
# 2.2.3 Basic map making
plot(world[3:6])
plot(world["pop"])
world_asia = world[world$continent == "Asia", ]
asia = st_union(world_asia)
plot(world["pop"], reset = FALSE)
plot(world["pop"], reset = FALSE)
plot(asia, add = TRUE, col = "red")
plot(world["continent"], reset = FALSE)
cex = sqrt(world$pop) / 10000
world_sf = st_as_sf(world_sp, "sf")
world_sf
source('~/Documents/GitHub/GeoComputationWithR/R/GeoComputation.R')
# 2.2.3 Basic map making
plot(world[3:6], add = TRUE) # similar to spplot() in sp package. Set color with "col = <color name>"
plot(world["pop"], add = TRUE)
world_sf
# Set working directory:
setwd("~/Documents/GitHub/GeoComputationWithR")
# ##### Contribute (Not Necesssary for Class) #####
# devtools::install_github("geocompr/geocompkg") #Reporduce code in the book.
# library(bookdown)
# bookdown::render_book("index.Rmd") # to build the book locally.
# browseURL("_book/index.html") # to view it.
# ##### Homework 1: Chapter 1 (Already completed ; No Need to open) #####
# Introduction
# 1.1 What is geocomputation?: Closely related to Geographic Information science, geomatics, geoinformatics, spatial information science, geoinfomatiion engineering and geographical data science (GDS).
# 1.2 Why use R for geocomputation?
# install.packages("leaflet")
library(leaflet)
popup = c("Bijesh", "Rajesh", "Shyam") # I changed author's name. Sorry!!!
leaflet() %>%
addProviderTiles("NASAGIBS.ViirsEarthAtNight2012") %>%
addMarkers(lng = c(-3, 23, 11),
lat = c(52, 53, 49),
popup = popup)
# 1.3 Software for geocomputation: QGIS, GRASS and SAGA built on C++, C++ is fasst but hard to learn compared to python. Rcpp made C++ more accessible. Java is another important program.Python is important program for geocomputing. Packages: osgeo, Shapely, NumPy, PyGeoProcessing.
# 1.4 R’s spatial ecosystem
# 1.5 The history of R-spatial
# 1.6 Exercises
# Q1. Think about the terms "GIS" and "geocomputation" described above. Which (if any) best describe the work you would like to do using geo* methods and software and why?
# Q2. Provide three reasons for using a scriptable language such as R for geocomputation instead of using an established GIS program such as QGIS?
# Q3. Name two advantages and two disadvantages of using mature vs recent packages for geographic data analysis (for example sf vs sp).
# Note: Python modules providing access to geoalgorithms include grass.script for GRASS, saga-python for SAGA-GIS, processing for QGIS and arcpy for ArcGIS.
# An overview of R’s spatial ecosystem can be found in the CRAN Task View on the Analysis of Spatial Data (see https://cran.r-project.org/web/views/Spatial.html).↩
# ##### Chapter 2: Geographic Data in R #####
# # Prerequisites:
# # Install Packages:
# # this step is to install library from github:
# install.packages("devtools") #install devtools package. Do not run of devtools is alread present in your machine.
# library(devtools) #load devtools before downloading packages from github.
# install_github("r-spatial/sf") #isntall sf package from github
# devtools::install_github("r-spatial/sf", type = "binary", force = TRUE) #This works without attaching devtools library.
# install.packages("raster")
# install.packages("spData")
# install.packages("devtools") #Install this package if you are installing packages from GitHub.
# devtools::install_github("Nowosad/spDataLarge", force = TRUE) #Need to add "Force = TRUE" to install this package in my MAC.
# install.packages("sf", type = "binary") #OSU IT People response: There is no such non-binary version. Homebrew and gdal packages are only necessary if you want to modify package. For, user, binary version is enough.
# Load Libraries.
library(raster) #class ad function for raster data.
library(spData) #load geographic data.
library(devtools) #used to install packages from GitHub.
library(spDataLarge) #Load larger geograpic Data.
library(sf) #class and function for vector data
# # Load data from SpDataLarge if you cannot install the package. Code from Github.
# if(!require(spDataLarge)) {
# download.file("https://github.com/Nowosad/spDataLarge/archive/master.zip", "spDataLarge.zip")
# unzip("spDataLarge.zip")
# files_rda = list.files("spDataLarge-master/data/", full.names = TRUE)
# sapply(files_rda, load, envir = .GlobalEnv)
# }
# # 2.1 Introduction
# # 2.2 Vector data
# London coordinates: c(-0.1, 51.5) is (longitude/Prime Meridiaan = degree east, Latitude/Equator = degree north) of the origin.
# In Projected CRS, above point = c(530000, 180000) is (Easting/Northing) means London is 530 km East and 180 km North of the norigin of CRS. This is British National Grid System.
# 2.2.1 An introduction to simple features:
vignette(package = "sf") # see which vignettes/descriptions are available
vignette("sf1") # an introduction to the package
names(world) #world is spatial object containing spatial and attribute columns returned by this function.
plot(world) #plot world.
summary(world["lifeExp"]) # geom is stick with the desired variable unless it is removed. MULTIPOLYGON is seen for countries with Island.
world_mini = world[1:2, 1:3] #A subset of first two row (from row 1 to rown 2) and three columns (from column 1 to column 3). This adds additional geographical data (geometry type, dimension, bbox) and CRS information ( epsg(SRID), proj4string ) and the presence of a geometry column (geom).
world_mini
View(world)
# 2.2.2 Why simple features (sf)? #Advantage: Cross transferrable.Also supports %>%, tmap, mapview, tidycensus.
library(sp)
world_sp = as(world, Class = "Spatial") # convert to spatial class.
world_sf = st_as_sf(world_sp, "sf") # spatial object convert back to sf.
world_sf
plot(world["pop"], reset = FALSE)
plot(asia, add = TRUE, col = "red")
?graphics ::plot
?par
# 2.2.4 Base plot arguments
plot(world["continent"], reset = FALSE, main = abc) #main = for title.
# 2.2.4 Base plot arguments
plot(world["continent"], reset = FALSE) #main = for title.
# 2.2.4 Base plot arguments
plot(world["continent"], reset = FALSE, main = "abc") #main = for title.
# 2.2.4 Base plot arguments
plot(world["continent"], reset = FALSE) #main = "abc" gives as title name as abc.
source('~/Documents/GitHub/GeoComputationWithR/R/GeoComputation.R')
?graphics ::plot #help
?par #help
plot(world["continent"], reset = FALSE) #main = "abc" gives as title name as abc.
world_cents = st_centroid(world, of_largest = TRUE)
# # I got this warning message after running above line of code. This might the resaon
plot(st_geometry(world_cents), add = TRUE, cex = cex)
india = world[world$name_long == "India", ]
plot(st_geometry(india), expandBB = c(0, 0.2, 0.1, 1), col = "gray", lwd = 3) #When I run this code, the map shrink down to really tiny size and moves down to mid-bottom of plotting region.
# # I got this warning message after running above line of code. This might the resaon why map of India shrunk down and moved to mid-bottom of plot.
# Warning messages:
# 1: In st_centroid.sf(world, of_largest = TRUE) :
# st_centroid assumes attributes are constant over geometries of x
# 2: In st_centroid.sfc(st_geometry(x), of_largest_polygon = of_largest_polygon) :
# st_centroid does not give correct centroids for longitude/latitude data
plot(st_geometry(world_cents), add = TRUE, cex = cex)
?graphics ::plot #help
?par #help
plot(world["continent"], reset = FALSE) #main = "abc" gives as title name as abc.
world_cents = st_centroid(world, of_largest = TRUE)
# # I got this warning message after running above line of code. This might the resaon why map of India shrunk down and moved to mid-bottom of plot.
# Warning messages:
# 1: In st_centroid.sf(world, of_largest = TRUE) :
# st_centroid assumes attributes are constant over geometries of x
# 2: In st_centroid.sfc(st_geometry(x), of_largest_polygon = of_largest_polygon) :
# st_centroid does not give correct centroids for longitude/latitude data
plot(st_geometry(world_cents), add = TRUE, cex = cex)
india = world[world$name_long == "India", ]
plot(st_geometry(india), expandBB = c(0, 0.2, 0.1, 1), col = "gray", lwd = 3) #When I run this code, the map shrink down to really tiny size and moves down to mid-bottom of plotting region.
? st_centroid
epsg(SRID)
proj4string()
st_crs(points_sfc) #Coordinate Reference System: NA.
lnd_point = st_point(c(0.1, 51.5)) # sfg object
lnd_geom = st_sfc(lnd_point, crs = 4326) # sfc object
lnd_attrib = data.frame( # data.frame object
name = "London",
temperature = 25,
date = as.Date("2017-06-21")
)
lnd_sf = st_sf(lnd_attrib, geometry = lnd_geom) # sf object
lnd_sf
class(lnd_sf)
lnd_point = st_point(c(0.1, 51.5)) # sfg object
lnd_point = st_point(c(0.1, 51.5)) # sfg object
lnd_point = st_point(c(0.1, 51.5)) # sfg object
lnd_point = st_point(c(0.1, 51.5)) # sfg object
lnd_attrib = data.frame( # data.frame
name = "London",
temperature = 25,
date = as.Date("2017-06-21")
)
lnd_sf = st_sf(lnd_attrib, geometry = lnd_geom) # sf object
Sys.time()
Sys.timezone(location = TRUE)
lnd_point = st_point(c(0.1, 51.5)) # sfg object
lnd_geom = st_sfc(lnd_point, crs = 4326) # sfc object
lnd_attrib = data.frame( # data.frame object
name = "London",
temperature = 25,
date = as.Date("2017-06-21")
)
lnd_sf = st_sf(lnd_attrib, geometry = lnd_geom) # sf object
source('~/Documents/GitHub/GeoComputationWithR/R/GeoComputation.R')
timezome
system.time(expr, gcFirst = TRUE)
install.packages(c("classInt", "lubridate", "optimx", "Rcpp", "reshape2", "sf", "spData", "survival", "usethis", "xml2"))
install.packages(c("classInt", "sf"))
install.packages(c("classInt", "sf"))
library(tidyverse)
library(sf) # classes and functions for vector data
library(raster) # classes and functions for raster data
library(spData) # load geographic data
library(spDataLarge) # load larger geographic data
library(sp)
vignette(package = "sf") # see which vignettes are available
vignette("sf1") # an introduction to the package
world
class(world)
str(world)
names(world)
colnames(world)
summary(world["lifeExp"])
plot(world)
devtools::install_github("Nowosad/spDataLarge, type = binary, force = TRUE")
install.packages("sf", type = "binary")
install.packages("sf", type = "binary")
devtools::install_github("Nowosad/spDataLarge", force = TRUE)
install.packages("sf", type = "binary", dependencies = TRUE)
install.packages("sf", type = "binary", dependencies = TRUE, force = TRUE)
devtools::install_github("r-spatial/sf", type = "binary", force = TRUE)
devtools::install_github("r-spatial/sf", type = "binary", force = TRUE)
install.packages("sf", type = "binary", dependencies = TRUE, force = TRUE)
names(world)
library(raster) #class ad function for raster data.
library(spData) #load geographic data.
library(devtools) #used to install packages from GitHub.
library(spDataLarge) #Load larger geograpic Data.
library(sf) #class and function for vector data
library(sp) #spatial feature.
library(leaflet)
popup = c("Robin", "Jakub", "Jannes")
leaflet() %>%
addProviderTiles("NASAGIBS.ViirsEarthAtNight2012") %>%
addMarkers(lng = c(-3, 23, 11),
lat = c(52, 53, 49),
popup = popup)
London coordinates: c(-0.1, 51.5) #c(long/easting, lat/northing)
Londoncoordinates: c(-0.1, 51.5) #c(long/easting, lat/northing)
# # 2.2 Vector data
names(world)
plot(world) #plot world.
# # ##### Install and Load Packages #####
# install.packages("tidyverse", dependencies = TRUE)
# install.packages("sf", type = "binary", dependencies = TRUE, force = TRUE)
# install.packages("raster", dependencies = TRUE)
# install.packages("spData", dependencies = TRUE)
# if (!require("devtools")) install.packages("devtools")
# devtools::install_github("Nowosad/spDataLarge", force = TRUE)
# install.packages("sp", dependencies = TRUE)
# install.packages("leaflet", dependencies = TRUE)
names(world)
plot(world) #plot world.
world$geom #coordinates of the country polygons.
summary(world["lifeExp"])
world_mini = world[1:2, 1:3] # world[row1:row2, column1:column3]
world_mini
View(world)
# # 2.2 Vector data
names(world)
plot(world) #plot world.
world$geom #coordinates of the country polygons.
install.packages(c("classInt", "gdtools", "leafem", "mapdeck", "mapview", "sf", "stars", "tmap", "tmaptools"))
install.packages(c("classInt", "gdtools", "mapdeck", "mapview", "sf", "stars", "tmap"))
names(world)
library(raster) #class ad function for raster data.
library(spData) #load geographic data.
library(devtools) #used to install packages from GitHub.
library(spDataLarge) #Load larger geograpic Data.
library(sf) #class and function for vector data
library(sp) #spatial feature.
library(leaflet)
popup = c("Robin", "Jakub", "Jannes")
leaflet() %>%
addProviderTiles("NASAGIBS.ViirsEarthAtNight2012") %>%
addMarkers(lng = c(-3, 23, 11),
lat = c(52, 53, 49),
popup = popup)
library(raster) #class ad function for raster data.
library(spData) #load geographic data.
library(devtools) #used to install packages from GitHub.
library(spDataLarge) #Load larger geograpic Data.
library(sf) #class and function for vector data
library(sp) #spatial feature.
library(leaflet)
popup = c("Robin", "Jakub", "Jannes")
leaflet() %>%
addProviderTiles("NASAGIBS.ViirsEarthAtNight2012") %>%
addMarkers(lng = c(-3, 23, 11),
lat = c(52, 53, 49),
popup = popup)
vignette(package = "sf") # see which vignettes/descriptions are available
vignette("sf1") # an introduction to the package
library(leaflet)
library(raster) #class ad function for raster data.
library(spData) #load geographic data.
library(devtools) #used to install packages from GitHub.
library(spDataLarge) #Load larger geograpic Data.
library(sf) #class and function for vector data
library(sp) #spatial feature.
vignette(package = "sf") # see which vignettes/descriptions are available
vignette("sf1") # an introduction to the package
names(world)
plot(world) #plot world.
world$geom
summary(world["lifeExp"])
# ##### Chapter 2: Geographic Data in R #####
# Set working directory:
setwd("~/Documents/GitHub/GeoComputationWithR")
library(leaflet)
library(raster) #class ad function for raster data.
library(spData) #load geographic data.
library(devtools) #used to install packages from GitHub.
library(spDataLarge) #Load larger geograpic Data.
library(sf) #class and function for vector data
library(sp) #spatial feature.
names(world)
plot(world) #plot world.
world$geom
summary(world["lifeExp"])
world_mini = world[1:2, 1:3] # world [row1:row2, column1:column3]
world_mini
View(world)
detach("package:spDataLarge", unload = TRUE)
library(spDataLarge)
names(world)
plot(world) #plot world.
# # ##### Install Packages #####
# install.packages("devtools", dependencies = TRUE)
# install.packages("tidyverse", dependencies = TRUE)
# install.packages("sf", dependencies = TRUE)
# install.packages("raster", dependencies = TRUE)
# install.packages("spData", dependencies = TRUE)
# if (!require("devtools")) install.packages("devtools")
# devtools::install_github("Nowosad/spDataLarge")
# install.packages("sp", dependencies = TRUE)
# devtools::install_github("r-spatial/sf", type = "binary", force = TRUE)
devtools::install_github("Nowosad/spDataLarge", force = TRUE)
plot(world) #plot world.
source('~/Documents/GitHub/GeoComputationWithR/Messy Code Backup.R')
source('~/Documents/GitHub/GeoComputationWithR/GeoComputation.R')
source('~/Documents/GitHub/GeoComputationWithR/GeoComputation.R')
source('~/Dropbox/OSU/PhD/Semester IV, Spring 2020/NREM 5130 Spatial and Non Spatial DBM/Spatial_DBM_R/Geocomputation With R/GeoComputationR.R')
source('~/Dropbox/OSU/PhD/Semester IV, Spring 2020/NREM 5130 Spatial and Non Spatial DBM/Spatial_DBM_R/Geocomputation With R/GeoComputationR.R')
popup = c("Robin", "Jakub", "Jannes")
leaflet() %>%
addProviderTiles("NASAGIBS.ViirsEarthAtNight2012") %>%
addMarkers(lng = c(-3, 23, 11),
lat = c(52, 53, 49),
popup = popup)
plot(world[["pop"]]) #treated as non-spatial data frame
plot(world[["pop"]]) #treated as non-spatial data frame
plot(world[3:6]) # similar to spplot(); multiple maps one for each variable
plot(world[["pop"]]) #treated as non-spatial data frame
world_asia = world[world$continent == "Asia", ]
asia = st_union(world_asia)
plot(world["pop"], reset = FALSE)
plot(asia, add = TRUE, col = "red")
names(world)
plot(world) #plot world.
world$geom
summary(world["lifeExp"])
world_mini = world[1:2, 1:3] # world [row1:row2, column1:column3]
world_mini
View(world)
world_sp = as(world, Class = "Spatial") # convert to spatial class.
world_sf = st_as_sf(world_sp, "sf") # spatial object convert back to sf.
world_sf
plot(world[3:6]) # similar to spplot(); multiple maps one for each variable
plot(world["pop"]) #treated as sf
plot(world[["pop"]]) #treated as non-spatial data frame
world_asia = world[world$continent == "Asia", ]
asia = st_union(world_asia)
plot(world["pop"], reset = FALSE)
plot(asia, add = TRUE, col = "red")
names(world)
plot(world) #plot world.
world$geom
world_mini = world[1:2, 1:3] # world [row1:row2, column1:column3]