-
-
Notifications
You must be signed in to change notification settings - Fork 320
/
Copy pathluft.R
195 lines (146 loc) · 8.1 KB
/
luft.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
source("installrequire.R")
installrequire(c("lubridate","dplyr","ggplot2"))
# library(xlsx)
# library(lubridate)
# library(dplyr)
# library(ggplot2)
###########################################################################
#####Preparation(only once)################################################
###########################################################################
#roh <- read.xlsx(file="table23032015135021029.xlsx", sheetIndex=1)
#names(roh) <- c("Messstelle", "Datetime", "Agg_Zeitraum", "Agg_Art", "NO2")
#roh$NO2 <- as.numeric(as.character(roh$NO2))
#roh$Datetime <- ymd_hm(roh$Datetime)
#roh <- roh %>% mutate(Woche=week(Datetime)) %>% mutate(Monat=month(Datetime)) %>% mutate(Date=as.Date(Datetime))
# script to read+preprocess (Makefile friendly)
# loads dataframe dat
source("readdata.R")
stop("readddata.R dysfct/not existent/moved to readairdat, stopping here...")
## Plots, to pdf
# pdf("plots.pdf")
png(width=1200,height=1000)
#Werte fuer PM2.5 im Zeitverlauf
p1 <- ggplot(filter(dat, type=="PPD42NS"), aes(timestamp2, P2, color=type)) + geom_point() + theme(axis.text.x = element_text(angle=90)) + geom_point(data=filter(dat, type == "GP2Y1010AU0F"), aes(timestamp2, P25, color=type)) + scale_y_log10()
#+ geom_point(data=filter(dat, type=="GP2Y1010AU0F"), aes(timestamp2, vo_raw, color=type))
print(p1)
# density plots
p1<-ggplot(dat, aes(x = P2)) + stat_density() + scale_x_log10()+ labs(title="P2 density (log scaled)")
print(p1)
p1<-ggplot(dat, aes(x = P1)) + stat_density() + scale_x_log10() + labs(title="P1 density (log scaled)")
print(p1)
p1<-ggplot(dat, aes(x = P1)) + stat_density() + scale_x_log10() + labs(title="P1 density (log scaled) by location_id")+ facet_wrap(~location_id); print(p1)
p1<-ggplot(dat, aes(x = P1)) + stat_density() + xlim(c(-1000,15645))+ labs(title="P1 density")
print(p1)
p1<-ggplot(dat, aes(x = P1)) + stat_density() + xlim(c(-1000,15645))+ labs(title="P1 density per location_id")+ facet_wrap(~location_id); print(p1)
p1<-ggplot(dat, aes(x = ratioP1)) + stat_density() + labs(title="ratioP1 density") + xlim(c(0,15))
print(p1)
p1<-ggplot(dat, aes(x = ratioP1)) + stat_density() + labs(title="ratioP1 density by location_id") + xlim(c(0,15)) + facet_wrap(~location_id)
print(p1)
p1<-ggplot(dat, aes(x = ratioP2)) + stat_density() + labs(title="ratioP2 density") + xlim(c(0,2))
print(p1)
p1<-ggplot(dat, aes(x = ratioP2)) + stat_density() + labs(title="ratioP2 density by location_id") + xlim(c(0,2)) + facet_wrap(~location_id)
print(p1)
p1<-ggplot(dat, aes(x = ratioP2)) + stat_density() + labs(title="ratioP2 density") + xlim(c(0,15))
#+ scale_x_log10()
print(p1)
p1<-ggplot(dat, aes(x = durP1)) + geom_density(color="red",trim=TRUE) +xlim(c(0,3446407))+ labs(title="durP1/durP2 densities (red/blue)") + geom_density(aes(x = durP2),color="blue",trim=TRUE)
print(p1)
p1<-ggplot(dat, aes(x = durP1)) + stat_density() +xlim(c(0,3446407))+ labs(title="durP2 density")
print(p1)
p1<-ggplot(dat, aes(x = P25)) + stat_density() + labs(title="P25 density (log scaled)") + scale_x_log10()
print(p1)
p1<-ggplot(dat, aes(x = P25)) + stat_density() + labs(title="P25 density") + xlim(c(2000,8000))
print(p1)
p1<-ggplot(dat, aes(x = P10)) + stat_density() + labs(title="P10 density") + xlim(c(8000,30000))
print(p1)
p1<-ggplot(dat, aes(x = P25)) + stat_density() + labs(title="P25 density/location_id") + xlim(c(2000,8000))+ facet_wrap(~location_id)
print(p1)
p1<-ggplot(dat, aes(x = P10)) + stat_density() + labs(title="P10 density/location_id") + xlim(c(8000,30000))+ facet_wrap(~location_id)
print(p1)
p1<-ggplot(dat, aes(x = P25)) + geom_density(aes(x = durP2),color="black",trim=TRUE) + labs(title="P25 (black), P10 (blue) densities") + xlim(c(0,50000))+ geom_density(aes(x = P10),color="blue",trim=TRUE)
print(p1)
p1<-ggplot(dat, aes(x = dust_density)) + geom_bar()+ labs(title="dust_density histogram") + xlim(c(-0.01,0.08)); print(p1)
p1<-ggplot(dat, aes(x = P10)) + stat_density() + labs(title="P10 density/sensor type") + xlim(c(8000,30000))+ facet_wrap(~type)
print(p1)
p1 <- ggplot(filter(dat, type=="PPD42NS"), aes(P1, P2)) + geom_point() +scale_x_log10() + scale_y_log10() + facet_wrap(~location_id)
print(p1)
p1 <- ggplot(filter(dat, type=="PPD42NS"), aes(P1, P2,color=as.double(timestamp2))) + scale_colour_continuous(high="yellow") + geom_point() +scale_x_log10() + scale_y_log10() + facet_wrap(~location_id)
print(p1)
p1 <- ggplot(dat, aes(P25, P10)) + geom_point() +scale_x_log10() + scale_y_log10() + facet_wrap(type~location_id, drop=TRUE,shrink=TRUE)
print(p1)
p1 <- ggplot(dat, aes(P1, P2)) + geom_point() +scale_x_log10() + scale_y_log10() + facet_wrap(type~location_id, drop=TRUE,shrink=TRUE)
print(p1)
p1 <- ggplot(dat, aes(ratioP1, ratioP2)) + geom_point() + facet_wrap(type~location_id, drop=TRUE,shrink=TRUE) +scale_x_log10() + scale_y_log10()
print(p1)
p1 <- ggplot(dat, aes(durP1, durP2)) + geom_point() + facet_wrap(type~location_id, drop=TRUE,shrink=TRUE) #+scale_x_log10() + scale_y_log10()
print(p1)
p1 <- ggplot(dat, aes(vo_raw, voltage)) + geom_point() + facet_wrap(type~location_id, drop=TRUE,shrink=TRUE) #+scale_x_log10() + scale_y_log10()
print(p1)
p1 <- ggplot(dat, aes(timestamp2, P1)) + geom_point() + facet_wrap(type~location_id, drop=TRUE,shrink=TRUE) + scale_y_log10()
print(p1)
p1 <- ggplot(dat) + geom_line(aes(timestamp2, P1)) + geom_line(aes(timestamp2, P2, color="red")) + facet_wrap(type~location_id,ncol=1, drop=TRUE,shrink=TRUE) + scale_y_log10()
print(p1)
# measurement times
p1 <- ggplot(dat) + geom_density(aes(x = timestamp2),color="blue",trim=TRUE,kernel="rectangular",width=0.1) + labs(title="Measurement density")
print(p1)
p1<- ggplot(dat) + geom_point(aes(timestamp2,P2,order = sample(seq_along(timestamp2))))
print(p1)
# since we do have dplyr and count, plot the "table" data
# TODO: make this work
# p1<-ggplot(count(dat,yday=as.POSIXlt(dat$timestamp2)$yday,type),aes(yday,n,col=type)) + geom_point()
# print(p1)
dev.off() # end plot to pdf
##random sample for histogram
#rand.ppd <- sample_n(ppd, 1000)
#p2 <- ggplot(data=filter(dat, type=="PPD42NS"), aes(P2)) + geom_histogram(binwidth=1/10)
##Daten fuer Sensoren anschauen
#head(dat)
#sample_n(filter(dat, type=="PPD42NS"), 10)
#sample_n(filter(dat, type=="GP2Y1010AU0F"), 10)
## some statistics about measurements
# look with table
# yday = day of year
table(dat$type,as.POSIXlt(dat$timestamp2)$yday,useNA = "ifany")
# how many NA's in P2?
table(dat$type,as.POSIXlt(dat$timestamp2)$yday,sapply(dat$P2,is.na),useNA = "no")
# how many NA's in P1?
table(dat$type,as.POSIXlt(dat$timestamp2)$yday,sapply(dat$P1,is.na),useNA = "no")
## official data sets
source("readdata_s_mitte.R")
if(!("sdat" %in% ls())){ # check if we have the data
warning("data not found, check readdata_s_mitte.R to download")
}else{ # plot
pdf("s-mitte.pdf",width=20, height=8)
for (y in names(sdat)[3:length(names(sdat))]){
p<-ggplot(sdat)+
geom_line(aes_string("datelt",y))+
labs(x="Zeit",
y=attr(sdat,"ylabel")[attr(sdat,"names")==y])
print(p)
}
# can you see sylvester? PMx > 500
# lets leave that out
y="pm25"
p<-ggplot(sdat[sdat$datelt>as.POSIXlt("2015-01-01 08:00:00"),])+
geom_line(aes_string("datelt",y))+
labs(title="Ohne Sylvester",
x="Zeit",
y=attr(sdat,"ylabel")[attr(sdat,"names")==y])
# PM10 daily means (Tagesmittelwerte), threshold is 50mug
sdat.yday<-aggregate(select(sdat,date,pm10),by=list(yday=sdat$datelt$yday),mean)
sdat.yday$datelt=as.POSIXlt(sdat.yday$date)
sdat.yday$above50<-factor(sdat.yday$pm10>50)
print(p)
y="pm10"
p<-ggplot(sdat[sdat$datelt>as.POSIXlt("2015-01-01 08:00:00"),])+
geom_line(aes_string("datelt",y))+
labs(title=paste("Ohne Sylvester, Überschreitungen:",sum(sdat.yday$pm10>50,na.rm=TRUE)),
x="Zeit",
y=attr(sdat,"ylabel")[attr(sdat,"names")==y])+
geom_point(data=sdat.yday,
aes(datelt,pm10,color=above50),size=5)+
scale_colour_discrete(h = c(120, 340), c = 100, l = 65, h.start = 30, direction = 1, na.value = "grey50")+
geom_hline(yintercept=50,lty=2)
print(p)
dev.off()
} # end if sdat