修订版 | 93e1937824e3d001eb4dedfa6d1082d27424d41c (tree) |
---|---|
时间 | 2011-11-19 19:51:09 |
作者 | lorenzo |
Commiter | lorenzo |
Some small modifications to the script that is now using faceting to explore
the data and generate panels.
@@ -6,9 +6,16 @@ | ||
6 | 6 | data$aggregate <- as.factor(data$aggregate) |
7 | 7 | |
8 | 8 | |
9 | +n_dis <- 6 #the number of neighbors is calculated for 6 | |
10 | +#distances | |
11 | + | |
12 | +n_mon <- 8 # monomer in each aggregate | |
13 | + | |
14 | +plot_individual <- 0 | |
9 | 15 | |
10 | 16 | |
11 | - | |
17 | +distance <- seq(1,2.25,by=0.25) #distances to calculate number | |
18 | + #neighbors | |
12 | 19 | |
13 | 20 | qs <- ddply(data, "aggregate", function(df) |
14 | 21 | quantile(df$eta, c(0.05, 0.25, 0.5, 0.75, 0.95))) |
@@ -105,4 +112,359 @@ | ||
105 | 112 | |
106 | 113 | tools::texi2dvi(fn,pdf=T) |
107 | 114 | |
115 | +######################################### | |
116 | + | |
117 | +if (plot_individual==1){ | |
118 | + | |
119 | + | |
120 | +b <- ggplot(data, aes(x=X1, y=eta)) + | |
121 | + opts( panel.background=theme_rect(fill='white', | |
122 | + size=1.5))+ | |
123 | + opts(panel.grid.minor = theme_blank())+ | |
124 | +opts(panel.grid.major = theme_blank())+ | |
125 | + opts(axis.ticks = theme_segment(colour = "black", size=1), | |
126 | + axis.ticks.length = unit(0.15, "cm"))+ | |
127 | + | |
128 | +geom_point(size=2)+ | |
129 | +facet_grid(~ aggregate)+ | |
130 | + xlab("Number of Neighbors at distance 1")+ | |
131 | + ylab("Shielding Factor $\\eta_i$")+ | |
132 | + opts(axis.title.x = theme_text(size = 20))+ | |
133 | + opts(axis.title.y = theme_text(size = 20, angle=90))+ | |
134 | + ## opts(axis.text.x = theme_text(size=15, colour="gray",vjust=1))+ | |
135 | + ## opts(axis.text.y = theme_text(size=15, colour="gray", hjust=1)) | |
136 | + opts(axis.text.x = theme_text(size=15, colour="black",vjust=1))+ | |
137 | + opts(axis.text.y = theme_text(size=15, colour="black", hjust=1)) | |
138 | + | |
139 | + | |
140 | +fn <-'correlation1.tex' | |
141 | + | |
142 | +tikz(fn, standAlone = TRUE, width=13,height=5) | |
143 | + | |
144 | + | |
145 | +print(b) | |
146 | +dev.off() | |
147 | + | |
148 | +tools::texi2dvi(fn,pdf=T) | |
149 | + | |
150 | + | |
151 | + | |
152 | +b <- ggplot(data, aes(x=X1.25, y=eta)) + | |
153 | + opts( panel.background=theme_rect(fill='white', | |
154 | + size=1.5))+ | |
155 | + opts(panel.grid.minor = theme_blank())+ | |
156 | +opts(panel.grid.major = theme_blank())+ | |
157 | + opts(axis.ticks = theme_segment(colour = "black", size=1), | |
158 | + axis.ticks.length = unit(0.15, "cm"))+ | |
159 | + | |
160 | +geom_point(size=2)+ | |
161 | +facet_grid(~ aggregate)+ | |
162 | + xlab("Number of Neighbors at distance 1")+ | |
163 | + ylab("Shielding Factor $\\eta_i$")+ | |
164 | + opts(axis.title.x = theme_text(size = 20))+ | |
165 | + opts(axis.title.y = theme_text(size = 20, angle=90))+ | |
166 | + ## opts(axis.text.x = theme_text(size=15, colour="gray",vjust=1))+ | |
167 | + ## opts(axis.text.y = theme_text(size=15, colour="gray", hjust=1)) | |
168 | + opts(axis.text.x = theme_text(size=15, colour="black",vjust=1))+ | |
169 | + opts(axis.text.y = theme_text(size=15, colour="black", hjust=1)) | |
170 | + | |
171 | + | |
172 | +fn <-'correlation125.tex' | |
173 | + | |
174 | +tikz(fn, standAlone = TRUE, width=13,height=5) | |
175 | + | |
176 | + | |
177 | +print(b) | |
178 | +dev.off() | |
179 | + | |
180 | +tools::texi2dvi(fn,pdf=T) | |
181 | + | |
182 | + | |
183 | + | |
184 | + | |
185 | + | |
186 | +b <- ggplot(data, aes(x=X1, y=eta)) + | |
187 | + opts( panel.background=theme_rect(fill='white', | |
188 | + size=1.5))+ | |
189 | + opts(panel.grid.minor = theme_blank())+ | |
190 | +opts(panel.grid.major = theme_blank())+ | |
191 | + opts(axis.ticks = theme_segment(colour = "black", size=1), | |
192 | + axis.ticks.length = unit(0.15, "cm"))+ | |
193 | + | |
194 | +geom_point(size=2)+ | |
195 | +facet_grid(~ aggregate)+ | |
196 | + xlab("Number of Neighbors at distance 1.5")+ | |
197 | + ylab("Shielding Factor $\\eta_i$")+ | |
198 | + opts(axis.title.x = theme_text(size = 20))+ | |
199 | + opts(axis.title.y = theme_text(size = 20, angle=90))+ | |
200 | + ## opts(axis.text.x = theme_text(size=15, colour="gray",vjust=1))+ | |
201 | + ## opts(axis.text.y = theme_text(size=15, colour="gray", hjust=1)) | |
202 | + opts(axis.text.x = theme_text(size=15, colour="black",vjust=1))+ | |
203 | + opts(axis.text.y = theme_text(size=15, colour="black", hjust=1)) | |
204 | + | |
205 | + | |
206 | +fn <-'correlation150.tex' | |
207 | + | |
208 | +tikz(fn, standAlone = TRUE, width=13,height=5) | |
209 | + | |
210 | + | |
211 | +print(b) | |
212 | +dev.off() | |
213 | + | |
214 | +tools::texi2dvi(fn,pdf=T) | |
215 | + | |
216 | + | |
217 | + | |
218 | +b <- ggplot(data, aes(x=X1.75, y=eta)) + | |
219 | + opts( panel.background=theme_rect(fill='white', | |
220 | + size=1.5))+ | |
221 | + opts(panel.grid.minor = theme_blank())+ | |
222 | +opts(panel.grid.major = theme_blank())+ | |
223 | + opts(axis.ticks = theme_segment(colour = "black", size=1), | |
224 | + axis.ticks.length = unit(0.15, "cm"))+ | |
225 | + | |
226 | +geom_point(size=2)+ | |
227 | +facet_grid(~ aggregate)+ | |
228 | + xlab("Number of Neighbors at distance 1")+ | |
229 | + ylab("Shielding Factor $\\eta_i$")+ | |
230 | + opts(axis.title.x = theme_text(size = 20))+ | |
231 | + opts(axis.title.y = theme_text(size = 20, angle=90))+ | |
232 | + ## opts(axis.text.x = theme_text(size=15, colour="gray",vjust=1))+ | |
233 | + ## opts(axis.text.y = theme_text(size=15, colour="gray", hjust=1)) | |
234 | + opts(axis.text.x = theme_text(size=15, colour="black",vjust=1))+ | |
235 | + opts(axis.text.y = theme_text(size=15, colour="black", hjust=1)) | |
236 | + | |
237 | + | |
238 | +fn <-'correlation175.tex' | |
239 | + | |
240 | +tikz(fn, standAlone = TRUE, width=13,height=5) | |
241 | + | |
242 | + | |
243 | +print(b) | |
244 | +dev.off() | |
245 | + | |
246 | +tools::texi2dvi(fn,pdf=T) | |
247 | + | |
248 | + | |
249 | + | |
250 | +b <- ggplot(data, aes(x=X2, y=eta)) + | |
251 | + opts( panel.background=theme_rect(fill='white', | |
252 | + size=1.5))+ | |
253 | + opts(panel.grid.minor = theme_blank())+ | |
254 | +opts(panel.grid.major = theme_blank())+ | |
255 | + opts(axis.ticks = theme_segment(colour = "black", size=1), | |
256 | + axis.ticks.length = unit(0.15, "cm"))+ | |
257 | + | |
258 | +geom_point(size=2)+ | |
259 | +facet_grid(~ aggregate)+ | |
260 | + xlab("Number of Neighbors at distance 1")+ | |
261 | + ylab("Shielding Factor $\\eta_i$")+ | |
262 | + opts(axis.title.x = theme_text(size = 20))+ | |
263 | + opts(axis.title.y = theme_text(size = 20, angle=90))+ | |
264 | + ## opts(axis.text.x = theme_text(size=15, colour="gray",vjust=1))+ | |
265 | + ## opts(axis.text.y = theme_text(size=15, colour="gray", hjust=1)) | |
266 | + opts(axis.text.x = theme_text(size=15, colour="black",vjust=1))+ | |
267 | + opts(axis.text.y = theme_text(size=15, colour="black", hjust=1)) | |
268 | + | |
269 | + | |
270 | +fn <-'correlation200.tex' | |
271 | + | |
272 | +tikz(fn, standAlone = TRUE, width=13,height=5) | |
273 | + | |
274 | + | |
275 | +print(b) | |
276 | +dev.off() | |
277 | + | |
278 | +tools::texi2dvi(fn,pdf=T) | |
279 | + | |
280 | + | |
281 | + | |
282 | +b <- ggplot(data, aes(x=X2.25, y=eta)) + | |
283 | + opts( panel.background=theme_rect(fill='white', | |
284 | + size=1.5))+ | |
285 | + opts(panel.grid.minor = theme_blank())+ | |
286 | +opts(panel.grid.major = theme_blank())+ | |
287 | + opts(axis.ticks = theme_segment(colour = "black", size=1), | |
288 | + axis.ticks.length = unit(0.15, "cm"))+ | |
289 | + | |
290 | +geom_point(size=2)+ | |
291 | +facet_grid(~ aggregate)+ | |
292 | + xlab("Number of Neighbors at distance 1")+ | |
293 | + ylab("Shielding Factor $\\eta_i$")+ | |
294 | + opts(axis.title.x = theme_text(size = 20))+ | |
295 | + opts(axis.title.y = theme_text(size = 20, angle=90))+ | |
296 | + ## opts(axis.text.x = theme_text(size=15, colour="gray",vjust=1))+ | |
297 | + ## opts(axis.text.y = theme_text(size=15, colour="gray", hjust=1)) | |
298 | + opts(axis.text.x = theme_text(size=15, colour="black",vjust=1))+ | |
299 | + opts(axis.text.y = theme_text(size=15, colour="black", hjust=1)) | |
300 | + | |
301 | + | |
302 | +fn <-'correlation225.tex' | |
303 | + | |
304 | +tikz(fn, standAlone = TRUE, width=13,height=5) | |
305 | + | |
306 | + | |
307 | +print(b) | |
308 | +dev.off() | |
309 | + | |
310 | +tools::texi2dvi(fn,pdf=T) | |
311 | + | |
312 | + | |
313 | +} | |
314 | + | |
315 | +################################################ | |
316 | + | |
317 | +#time to generate a new data set for a better faceting plot | |
318 | + | |
319 | +n_agg <- length(levels(data$aggregate)) | |
320 | + | |
321 | +agg_label <- c() | |
322 | +nei_dist <- c() | |
323 | +number_nei <- c() | |
324 | +eta_long <- c() | |
325 | + | |
326 | + | |
327 | +ld <- length(distance) | |
328 | + | |
329 | + | |
330 | +for (i in seq(n_agg)){ | |
331 | + | |
332 | +for (m in seq(ld)){ | |
333 | + | |
334 | +temp <- rep(distance[m], n_mon) | |
335 | +nei_dist <- c(nei_dist,temp) | |
336 | + | |
337 | + | |
338 | +} | |
339 | + | |
340 | + | |
341 | + | |
342 | +} | |
343 | + | |
344 | +for (i in seq(n_agg)){ | |
345 | + | |
346 | +agg_label <- c(agg_label,rep(i,n_mon*ld)) | |
347 | + | |
348 | +#nei_dist <- c(nei_dist,rep(distance,n_mon)) | |
349 | + | |
350 | +#number_nei <- c(number_nei, ) | |
351 | + | |
352 | +sel <- which(data$aggregate==i) | |
353 | + | |
354 | +data_temp <- data[sel,3:(3+ld-1)] | |
355 | + | |
356 | +data_temp <- as.matrix(data_temp) | |
357 | +dim(data_temp) <- c(ld*n_mon,1) | |
358 | + | |
359 | +number_nei <- c(number_nei,data_temp) | |
360 | + | |
361 | + | |
362 | + | |
363 | + | |
364 | +eta_long <- c(eta_long,rep(data$eta[sel],length(distance))) | |
365 | + | |
366 | + | |
367 | +} | |
368 | + | |
369 | + | |
370 | +data_new <- cbind(eta_long, agg_label,nei_dist,number_nei ) | |
371 | +data_new <- as.data.frame(data_new) | |
372 | + | |
373 | + | |
374 | +names(data_new) <- c("eta","aggregate_number", | |
375 | + "distance", "number_nei") | |
376 | + | |
377 | +data_new$aggregate_number<-as.factor(data_new$aggregate_number) | |
378 | +data_new$distance<-as.factor(data_new$distance) | |
379 | + | |
380 | + | |
381 | +b <- ggplot(data_new, aes(x=number_nei, y=eta)) + | |
382 | + opts( panel.background=theme_rect(fill='white', | |
383 | + size=1.5))+ | |
384 | + opts(panel.grid.minor = theme_blank())+ | |
385 | +opts(panel.grid.major = theme_blank())+ | |
386 | + opts(axis.ticks = theme_segment(colour = "black", size=1), | |
387 | + axis.ticks.length = unit(0.15, "cm"))+ | |
388 | + | |
389 | +geom_point(size=2)+ | |
390 | +facet_grid(distance~ aggregate_number)+ | |
391 | + xlab("Number of neighbors inside the shell")+ | |
392 | + ylab("Shielding Factor $\\eta_i$")+ | |
393 | + opts(axis.title.x = theme_text(size = 20))+ | |
394 | + opts(axis.title.y = theme_text(size = 20, angle=90))+ | |
395 | + ## opts(axis.text.x = theme_text(size=15, colour="gray",vjust=1))+ | |
396 | + ## opts(axis.text.y = theme_text(size=15, colour="gray", hjust=1)) | |
397 | + opts(axis.text.x = theme_text(size=15, colour="black",vjust=1))+ | |
398 | + opts(axis.text.y = theme_text(size=15, colour="black", hjust=1)) | |
399 | + | |
400 | + | |
401 | +fn <-'correlation_total.tex' | |
402 | + | |
403 | +tikz(fn, standAlone = TRUE, width=15,height=15) | |
404 | + | |
405 | + | |
406 | +print(b) | |
407 | +dev.off() | |
408 | + | |
409 | +tools::texi2dvi(fn,pdf=T) | |
410 | + | |
411 | + | |
412 | +##########################à | |
413 | + | |
414 | +b <- ggplot(data_new, aes(x=number_nei, y=eta)) + | |
415 | + opts( panel.background=theme_rect(fill='white', | |
416 | + size=1.5))+ | |
417 | + opts(panel.grid.minor = theme_blank())+ | |
418 | +opts(panel.grid.major = theme_blank())+ | |
419 | + opts(axis.ticks = theme_segment(colour = "black", size=1), | |
420 | + axis.ticks.length = unit(0.15, "cm"))+ | |
421 | + | |
422 | +geom_point(size=2)+ | |
423 | +facet_grid( ~ distance)+ | |
424 | + xlab("Number of neighbors inside the shell")+ | |
425 | + ylab("Shielding factor $\\eta_i$")+ | |
426 | + opts(axis.title.x = theme_text(size = 20))+ | |
427 | + opts(axis.title.y = theme_text(size = 20, angle=90))+ | |
428 | + ## opts(axis.text.x = theme_text(size=15, colour="gray",vjust=1))+ | |
429 | + ## opts(axis.text.y = theme_text(size=15, colour="gray", hjust=1)) | |
430 | + opts(axis.text.x = theme_text(size=15, colour="black",vjust=1))+ | |
431 | + opts(axis.text.y = theme_text(size=15, colour="black", hjust=1)) | |
432 | + | |
433 | + | |
434 | +fn <-'correlation_total_aggregates_together.tex' | |
435 | + | |
436 | +tikz(fn, standAlone = TRUE, width=15,height=5) | |
437 | + | |
438 | + | |
439 | +print(b) | |
440 | +dev.off() | |
441 | + | |
442 | +tools::texi2dvi(fn,pdf=T) | |
443 | + | |
444 | + | |
445 | +#################################################### | |
446 | + | |
447 | +cor_data <- seq(ld) | |
448 | + | |
449 | +for (i in seq(ld)){ | |
450 | + | |
451 | +sel <- which(data_new$distance==distance[i]) | |
452 | + | |
453 | +my_corr <- cor(data_new$eta[sel],data_new$number_nei[sel]) | |
454 | + | |
455 | +cor_data[i] <- my_corr | |
456 | + | |
457 | + | |
458 | +} | |
459 | + | |
460 | + | |
461 | +cor_data <- abs(cor_data) | |
462 | + | |
463 | +print ("cor_data is, ") | |
464 | +print(cor_data) | |
465 | + | |
466 | + | |
467 | +write.csv(cor_data,"correlation_data.csv", row.names=FALSE) | |
468 | + | |
469 | + | |
108 | 470 | print("So far so good") |