-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunctionsPlot.R
More file actions
132 lines (109 loc) · 5.03 KB
/
Copy pathfunctionsPlot.R
File metadata and controls
132 lines (109 loc) · 5.03 KB
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
#create plot(line) for given Hz
createPlotHertz <- function(hertz, sampleSize = nrow(sample)){
columnName <- paste("Hz",hertz,sep="")
sampleTemp <- sample[seq(0,nrow(sample),nrow(sample)/sampleSize),]
plot <- ggplot(data = sampleTemp,
aes(x = timeMs, y = sampleTemp[columnName])) +
geom_line() +
ggtitle(paste(hertz,"Hz - Sample size:", sampleSize)) +
scale_y_continuous(name="Value", labels = comma) +
scale_x_continuous(name = "Elapsed Ms" , breaks = seq(0,max(sample$timeMs),2000))
return(plot)
}
#create plot(line) for given Hz
createPlotHertzBar <- function(hertz){
columnName <- paste("Hz",hertz,sep="")
sampleTemp <- sample
plot <- ggplot(data = sampleTemp,
aes(x = timeMs, y = sampleTemp[columnName],fill = sampleTemp[columnName] >500000)) +
geom_bar(stat = "identity") +
ggtitle(paste(hertz,"Hz")) +
scale_y_continuous(name="Value", labels = comma) +
scale_x_continuous(name = "Elapsed Ms" , breaks = seq(0,max(sample$timeMs),round(max(sample$timeMs)/20)),0) +
scale_fill_manual(name = 'Labeled', values = setNames(c('brown','cadetblue4'),c(T, F)))
return(plot)
}
#create plot(line) for given ms
createPlotMs <- function(milliSecond,sampleSize = ncol(sample)-2){
sampleTemp <- as.data.frame(t(sample[toString(milliSecond),2:ncol(sample)]))
sampleTemp$hertz <- as.numeric(substr(rownames(sampleTemp),3,nchar(rownames(sampleTemp))))
names(sampleTemp) <- c("value","hertz")
plot <- ggplot(data = sampleTemp[seq(0,nrow(sampleTemp),nrow(sampleTemp)/sampleSize),],
aes(x = hertz, y = value)) +
geom_bar(stat = "identity") +
ggtitle(paste(milliSecond, "ms" ))
return(plot)
}
#create plot(bar) Average for given timeframe and Hz range
createPlotHzAvgBar <- function(milliSecondFrom = 1,milliSecondTo = 60000, hertzFrom = 12, hertzTo =24000 ){
#save parameter's column index
hzLower<- grep(paste("^Hz",hertzFrom,"$",sep=""), colnames(sample))-1
hzUpper<- grep(paste("^Hz",hertzTo,"$",sep=""), colnames(sample))-1
tempDf <- sample %>%
filter(timeMs > milliSecondFrom & timeMs < milliSecondTo) %>%
select(-timeMs) %>%
select(hzLower:hzUpper)
tempDf <- as.data.frame(colSums(tempDf))
tempDf$hertz <- as.numeric(substr(rownames(tempDf),3,nchar(rownames(tempDf))))
rownames(tempDf) <-NULL
names(tempDf) <- c("value","hertz")
title <- paste("Ms: ",as.numeric(milliSecondFrom)," - ",milliSecondTo," ","Hz: ",hertzFrom," - ",hertzTo,sep="" )
plot <- ggplot(data = tempDf,
aes(x = hertz, y = value)) +
geom_bar(stat = "identity") +
ggtitle(title) +
scale_y_continuous(name="Value", labels = comma) +
scale_x_continuous(name = "Hz" , breaks = seq(0,max(tempDf$hertz),2000))
return(plot)
}
#create plot(line) Average for given timeframe and Hz range
createPlotHzAvgLine <- function(milliSecondFrom = 1,milliSecondTo = 60000, hertzFrom = 12, hertzTo =24000 ){
#save parameter's column index
hzLower<- grep(paste("^Hz",hertzFrom,"$",sep=""), colnames(sample))-1
hzUpper<- grep(paste("^Hz",hertzTo,"$",sep=""), colnames(sample))-1
tempDf <<- sample %>%
filter(timeMs > milliSecondFrom & timeMs < milliSecondTo) %>%
select(-timeMs) %>%
select(hzLower:hzUpper)
tempDf <<- as.data.frame(colSums(tempDf))
tempDf$hertz <<- as.numeric(substr(rownames(tempDf),3,nchar(rownames(tempDf))))
rownames(tempDf) <<-NULL
names(tempDf) <<- c("value","hertz")
plotTitle <- paste("Ms: ",milliSecondFrom," - ",milliSecondTo,"\n","Hz: ",hertzFrom," - ",hertzTo,sep="" )
plot <- ggplot(data = tempDf,
aes(x = hertz, y = value)) +
geom_line() +
ggtitle(plotTitle) +
scale_y_continuous(name="Value", labels = comma) +
scale_x_continuous(name = "Hz" , breaks = seq(0,max(tempDf$hertz),1000))
return(plot)
}
#create multiplot
multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {
library(grid)
# Make a list from the ... arguments and plotlist
plots <- c(list(...), plotlist)
numPlots = length(plots)
# If layout is NULL, then use 'cols' to determine layout
if (is.null(layout)) {
# Make the panel
# ncol: Number of columns of plots
# nrow: Number of rows needed, calculated from # of cols
layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
ncol = cols, nrow = ceiling(numPlots/cols))
}
if (numPlots==1) {
print(plots[[1]])
} else {
# Set up the page
grid.newpage()
pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))
# Make each plot, in the correct location
for (i in 1:numPlots) {
# Get the i,j matrix positions of the regions that contain this subplot
matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))
print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
layout.pos.col = matchidx$col))
}
}
}