forked from andrw-jns/funnel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testExample.R
57 lines (37 loc) · 1.47 KB
/
testExample.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
# test example for funl_Data
library(testthat) # test_that
# confirm correct library path
test_that('correctlibPath', {
expect_equal(.libPaths()
, 'C:/Program Files/R/R-3.4.1/library')
})
# required packages
library(tidyverse)
# 1 setup options -------------------------------------------------------------
baseDir <- c("C:/Projects")
projectDir <- paste0(baseDir, "/exFunnel")
setwd(projectDir)
# source funlData
source("./funlData.R")
# 2 read test data -----------------------------------------------------------
testData <- read.csv("testData.csv"
, header = TRUE
, stringsAsFactors = FALSE)
# does it work ----------------------------------------------------------------
funnelPlotData <- funl_Data(testData, col.unit = "practice", col.group = "grp", col.O = "O", col.n = "n", col.rt = "rt"
, target = NULL, smoothness = 100, fnlMinEvents = NULL, fnlMaxEvents = NULL)
# preview result
funnelPlotData
# a quick plot
plotFunnels <- funnelPlotData[[1]]
plotUnits <- funnelPlotData[[2]]
plotUnits <- plotUnits %>%
left_join(testData, "practice")
funlPlot <-
ggplot(plotFunnels) +
geom_line(aes(x = n, y = fnlLow, group = fnlLimit), linetype = "44") +
geom_line(aes(x = n, y = fnlHigh, group = fnlLimit), linetype = "44") +
geom_line(aes(x = n, y = target)) +
#geom_hline(aes(yintercept = target)) +
geom_point(aes(x = n, y = rt, color = status), data = plotUnits)
print(funlPlot)