-
Notifications
You must be signed in to change notification settings - Fork 0
/
playground.R
47 lines (32 loc) · 1.53 KB
/
playground.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
#### DATE ####
infotable$when <- as.POSIXct((strptime(infotable$when, format = "%Y-%m-%d %H:%M:%S")))
# add more date related columns eg. from when = "2015-09-06 10:01:07"
# 2015
infotable$year <- strftime(infotable$when, "%Y")
infotable$year <- as.integer(infotable$year)
# September
infotable$month <- strftime(infotable$when, "%B")
months <- c("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December")
infotable$month <- factor(infotable$month, levels = months)
# 36
infotable$week <- strftime(infotable$when, "%V")
infotable$week <- as.integer(infotable$week)
# Sunday
infotable$WeekDay <- weekdays(strptime(infotable$when, "%Y-%m-%d" ))
week <- c("Sunday", "Saturday", "Friday", "Thursday", "Wednesday", "Tuesday", "Monday")
infotable$WeekDay <- factor(infotable$WeekDay, levels = week)
# 10 (hour of start)
infotable$hour <- strftime(infotable$when, "%H")
infotable$hour <- as.integer(infotable$hour)
#### colors for sports ####
a1<-c("CYCLING", "HIKING", "MOUNTAIN_BIKING", "POOL_SWIMMING", "WALKING", "RUNNING")
b1<-c("yellow", "red", "orange", "blue", "green", "brown")
a<-c("RUNNING", "HIKING", "MOUNTAIN_BIKING", "POOL_SWIMMING", "CYCLING", "WALKING")
b<-c("yellow", "red", "orange", "blue", "green", "brown")
# I can set sports colors, but not the stack order (yet)
ggplot(aggr.dist, aes(month, total.dist, fill=sport))+
geom_bar(stat="identity", position = "stack") +
scale_fill_manual(breaks = a, values = b)
attributes(aggr.dist$sport)
levels(aggr.dist$sport)