-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaptweets2.r
124 lines (105 loc) · 4.13 KB
/
maptweets2.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
library(mapproj)
GAME = "game6"
## Instantiating data.frames with data.
tweets <- read.delim(paste("data/", GAME, "_clean.txt", sep=""),
header=FALSE, sep="\t", quote=NULL, row.names=NULL,
encoding = 'UTF-8')
timestamps <- read.delim(paste("data/", GAME, "_time.txt", sep=""),
header=TRUE, sep='\t', row.names=NULL)
count <- read.delim(paste("data/", GAME, "_count.txt", sep=""),
header=TRUE, sep='\t', row.names=NULL)
tweets_times <- merge(tweets, timestamps, by.x='V1', by.y='TIME')
tweets_full <- merge(tweets_times, count, by.x='V1', by.y='TIME')
tweets_full <- transform(tweets_full, V4=as.numeric(as.character(V4)))
## Setting up US map. Refer to Nathan's tutorial for a nice-looking map.
## Modify xlim, ylim s.t. tweets aren't floating in whitespace.
xlim <- c(-171.738281, -56.601563)
ylim <- c(12.039321, 71.856229)
## Creating list of coordinates for every tweet.
for ( j in 1:5) {
longMavs_t_1 = c()
longMavs_t_2 = c()
longMavs_t_3 = c()
longMavs_t_4 = c()
longMavs_t_5 = c()
latMavs_t_1 = c()
latMavs_t_2 = c()
latMavs_t_3 = c()
latMavs_t_4 = c()
latMavs_t_5 = c()
longHeat_t_1 = c()
longHeat_t_2 = c()
longHeat_t_3 = c()
longHeat_t_4 = c()
longHeat_t_5 = c()
latHeat_t_1 = c()
latHeat_t_2 = c()
latHeat_t_3 = c()
latHeat_t_4 = c()
latHeat_t_5 = c()
}
longMavs_t = c()
latMavs_t = c()
longHeat_t = c()
latHeat_t = c()
for ( tt in max(tweets_full$DELTA):min(tweets_full$DELTA) ) {
filename = paste("~/Desktop/ps/", GAME, "_", tt, ".ps", sep="")
postscript(filename, width=11, height=7)
m <- map('world', col="#f0f0f0", bg = "#ffffff", fill = TRUE, lwd=0.001,
ylim = ylim, xlim = xlim)
longMavs_t = longMavs_t_1
latMavs_t = latMavs_t_1
longHeat_t = longHeat_t_1
latHeat_t = latHeat_t_1
longMavs_t_2 = longMavs_t_1
longMavs_t_3 = longMavs_t_2
longMavs_t_4 = longMavs_t_3
longMavs_t_5 = longMavs_t_4
latMavs_t_2 = latMavs_t_1
latMavs_t_3 = latMavs_t_2
latMavs_t_4 = latMavs_t_3
latMavs_t_5 = latMavs_t_4
longHeat_t_2 = longHeat_t_1
longHeat_t_3 = longHeat_t_2
longHeat_t_4 = longHeat_t_3
longHeat_t_5 = longHeat_t_4
latHeat_t_2 = latHeat_t_1
latHeat_t_3 = latHeat_t_2
latHeat_t_4 = latHeat_t_3
latHeat_t_5 = latHeat_t_4
tempData = subset(tweets_full, DELTA == tt)
for ( i in 1:nrow(tempData) ) {
long = tempData$V3[i]
if ( !is.na(long) ) {
lat = tempData$V4[i]
if ( tempData$MAVS[i] > tempData$HEAT[i] ) {
longMavs_t = append(longMavs_t, long)
latMavs_t = append(latMavs_t, lat)
} else if ( tempData$MAVS[i] < tempData$HEAT[i] ) {
longHeat_t = append(longHeat_t, long)
latHeat_t = append(latHeat_t, lat)
}
}
}
## Also, use col = HEX to color the points.
## Mavs = #0065B0, Heat = #BA3636
points(longMavs_t, latMavs_t, col = '#0065B0', pch = ".", cex = 2)
points(longMavs_t_1, latMavs_t_1, col = '#0065B0', pch = ".", cex = 2)
points(longMavs_t_2, latMavs_t_2, col = '#0065B0', pch = ".", cex = 2)
points(longMavs_t_3, latMavs_t_3, col = '#0065B0', pch = ".", cex = 2)
points(longMavs_t_4, latMavs_t_4, col = '#0065B0', pch = ".", cex = 2)
points(longMavs_t_5, latMavs_t_5, col = '#0065B0', pch = ".", cex = 2)
points(longHeat_t, latHeat_t, col = '#BA3636', pch = ".", cex = 2)
points(longHeat_t_1, latHeat_t_1, col = '#BA3636', pch = ".", cex = 2)
points(longHeat_t_2, latHeat_t_2, col = '#BA3636', pch = ".", cex = 2)
points(longHeat_t_3, latHeat_t_3, col = '#BA3636', pch = ".", cex = 2)
points(longHeat_t_4, latHeat_t_4, col = '#BA3636', pch = ".", cex = 2)
points(longHeat_t_5, latHeat_t_5, col = '#BA3636', pch = ".", cex = 2)
dev.off()
}
# NEXT:
# DONE> Do tweets have NBA finals references? If so, add to coords.
# 2. Do this for every second of data in the set.
# >> Test with Mavs data for a small subset first.
# 3. Create maps for every second of the game.
# 4. Stitch together using...what?