@@ -131,16 +131,91 @@ plot.years <- function(topic) {
131
131
plot(compute.fraction(topic ))
132
132
}
133
133
134
- plot.fraction.years <- function (topic ) {
135
- quartz(title = topic , width = 5 , height = 5 )
134
+ plot.fraction.years <- function (topic , new = TRUE , use.words = FALSE , ylim = 50 ) {
135
+ if (use.words )
136
+ title <- topics [topics $ name == topic ,]$ words
137
+ else
138
+ title <- topic
139
+
140
+
141
+ if (new )
142
+ quartz(title = title , width = 5 , height = 5 )
143
+
136
144
m <- compute.fraction.matrix(topic )
137
145
138
146
# # convert to percentage
139
147
m [,2 ] <- m [,2 ] * 100
140
148
141
149
plot(m [,1 ], m [,2 ], pch = 16 , col = " blue" ,
142
- main = topic , ylab = " Documents (%)" , xlab = " Year" , ylim = c(0 ,50 ))
143
- abline(lm(fraction ~ year , as.data.frame(m )))
150
+ main = title , ylab = " Documents (%)" , xlab = " Year" , ylim = c(0 ,ylim ))
151
+ abline(lm(fraction ~ year , as.data.frame(m )), col = gray(0.5 ))
152
+
153
+ if (new ) {
154
+ filename <- paste(topic , " -trend.pdf" , sep = " " )
155
+ quartz.save(filename , type = " pdf" )
156
+ }
157
+ }
158
+
159
+ plot.years.separate <- function (topics ) {
160
+ for (t in topics ) {
161
+ plot.fraction.years(t )
162
+ }
163
+ }
164
+
165
+ run <- function () {
166
+ plot.fraction.years(" Z1321" , ylim = 12 )
167
+ plot.fraction.years(" Z1327" , ylim = 10 )
168
+ plot.fraction.years(" Z1315" , ylim = 8 )
169
+ plot.fraction.years(" Z12311" , ylim = 12 )
170
+ plot.fraction.years(" Z13032" , ylim = 10 )
171
+ plot.fraction.years(" Z2995" , ylim = 8 )
172
+ }
173
+
174
+ plot.downward <- function () {
175
+ yl <- 15
176
+ plot.fraction.years(" Z3159" , ylim = yl )
177
+ plot.fraction.years(" Z3384" , ylim = yl )
178
+ plot.fraction.years(" Z3302" , ylim = yl )
179
+ plot.fraction.years(" Z3192" , ylim = yl )
180
+ plot.fraction.years(" Z3158" , ylim = yl )
181
+ }
182
+
183
+ plot.upward <- function () {
184
+ yl <- 15
185
+ plot.fraction.years(" Z370" , ylim = yl )
186
+ plot.fraction.years(" Z344" , ylim = yl )
187
+ plot.fraction.years(" Z3207" , ylim = yl )
188
+ plot.fraction.years(" Z326" , ylim = yl )
189
+ plot.fraction.years(" Z3204" , ylim = yl )
190
+ }
191
+
192
+
193
+ plot.toplevel.years <- function () {
194
+ plot.topic.years(c(" Z77" , " Z72" , " Z79" , " Z711" , " Z73" , " Z74" , " Z71" ,
195
+ " Z713" , " Z76" , " Z712" , " Z75" , " Z78" , " Z710" ),
196
+ TRUE )
197
+ }
198
+
199
+ plot.topic.years <- function (ts , use.words = FALSE ) {
200
+ quartz(title = " Topic Trend" , width = 15 , height = 9 )
201
+
202
+ nrows <- ceiling(length(ts ) / 5 )
203
+ opar <- par(no.readonly = TRUE )
204
+ par(mfrow = c(nrows , 5 ), mar = c(2 ,2 ,2 ,1 ))
205
+
206
+ for (topic in ts ) {
207
+ m <- compute.fraction.matrix(topic )
208
+ words <- topics [topics $ name == topic ,]$ words
209
+
210
+ # # convert to percentage
211
+ m [,2 ] <- m [,2 ] * 100
212
+
213
+ plot(m [,1 ], m [,2 ], pch = 16 , col = " blue" ,
214
+ ylim = c(0 ,50 ),ann = FALSE )
215
+ abline(lm(fraction ~ year , as.data.frame(m )), col = gray(0.5 ))
216
+ title(main = topic )
217
+ }
218
+ par(opar )
144
219
}
145
220
146
221
# # Computes regression coefficients for topics. The data is saved if a filename
@@ -152,7 +227,8 @@ compute.coefficients <- function(filename=NULL, topics.selected=NULL) {
152
227
coefficients <- find.coefficients(topics.selected )
153
228
lines <- fit.fraction.lm.topics(topics.selected )
154
229
155
- indices <- sapply(rownames(coefficients ), function (t ) { which(topics $ name == t ) })
230
+ indices <- sapply(rownames(coefficients ),
231
+ function (t ) { which(topics $ name == t ) })
156
232
data <- cbind(topics [indices ,], coefficients , lines )
157
233
158
234
if (! is.null(filename )) {
0 commit comments