-
Notifications
You must be signed in to change notification settings - Fork 12
/
coffee.R
152 lines (117 loc) · 3.16 KB
/
coffee.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
# Aim: create simple data frame and map for use in Geocomputation with R course
# Learn basic of R
# create object
x = 1:3
y = x^2
# plot objects
plot(x, y)
person_name = c("dani", "alistair", "robin")
n_coffee = c(10, 15, 6)
hometown = c("zaragoza", "edinburgh", "hereford")
likes_tea = c(TRUE, FALSE, FALSE)
class(person_name)
class(n_coffee)
class(likes_tea)
person_name[1:2]
person_name[likes_tea]
person_name[n_coffee >= 10]
coffee_df1 = tibble::tibble(
person_name,
n_coffee,
hometown
)
#---------------------table by the window----------------
# recreation example
person_name <-
c("olivia", "daniel", "phil", "claudia") # this is a vector (a series of vectors of the same class)
n_coffee <- c(7, 3, 10, 14)
hometown <- c("doncaster", "harlech", "pretoria", "mexico_city")
coffee_df_tbtw <- data.frame(person_name,
n_coffee,
hometown)
#---------------------------------------------------------
#added data from back table
name=c("Izzie","Greg", "Katherine", "Jeremy", "Kara")
coffee=c(2,3,5,2,0)
town=c("High Wickham","Budapest","Bristol","Chester","Buffalo")
new_coffee = data.frame(name,coffee,town)
new_coffee
#SANDRA_PAUL_MAGD
#create object
x=1:3
y=x^2
#plot objects
plot(x, y)
person_name = c("sandra", "Magd", "Paul")
n_coffee=c(1364,-533,2)
hometown=c("Triptis", "Damascus", "London")
person_name[n_coffee>= 0]
coffee_table_df = data.frame(
person_name,
n_coffee,
hometown
)
#add more data
person_name <- c("Elle", "Nick", "Dan")
n_coffee <- c(3, 9, 20)
hometown <- c("London", "Cumbria", "Kent")
coffee_df2 <- data.frame(person_name, n_coffee, hometown)
person_name = c("lauren",
"Harriet",
"Tony",
"James",
"Monika")
n_coffee = c(5,
0,
6,
5,
5)
hometown = c("Twickenham",
"London",
"Bristol",
"Walsall",
"Nysa")
coffee_df3 = data.frame(person_name, n_coffee, hometown)
#add in data
person_name = c("sam", "fazila","george", "david", "josh")
n_coffee = c(9, 0,15,10, 20)
hometown = c("london", "london","athens","carlisle","london")
likes_tea = c(TRUE,TRUE,TRUE,TRUE,FALSE)
class(person_name)
class(n_coffee)
class(hometown)
geotable = data.frame(
person_name,
n_coffee,
hometown
)
person_name = c("Humphrey", "James", "Harvinder", "Tom")
n_coffee = c(9, 7, 0, 5)
hometown = c("Worcester", "Cheltenham", "Hayes", "Luton")
coffee_df4 = data.frame(person_name, n_coffee, hometown)
coffee_all = rbind(
coffee_df1,
coffee_df2,
coffee_df3,
coffee_df4,
coffee_df_tbtw,
geotable,
coffee_table_df
)
# library(tmaptools) # note :: means 'from this package'
coordinates = tmaptools::geocode_OSM(coffee_all$hometown)
coffee_with_coords = tibble::tibble(
person_name = coffee_all$person_name,
n_coffee = coffee_all$n_coffee,
hometown = coffee_all$hometown,
lon = coordinates$lon,
lat = coordinates$lat
)
library(sf)
coords = c("lon", "lat")
coffee_sf = st_as_sf(coffee_with_coords, coords = coords)
plot(coffee_sf)
library(tmap)
tmap_mode("view")
tm_shape(coffee_sf) + tm_dots()
write.csv(coffee_df, "coffee.csv")