-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotRangeChart.R
98 lines (95 loc) · 2.17 KB
/
plotRangeChart.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
plotRangeChart <- function(df, chart_type, pl) {
## X-bar and s or I-MR
if(chart_type == 'X-bar chart') {
chart1 <- 'X-bar chart'
chart2 <- 's chart'
}
if(chart_type == 'I chart') {
chart1 <- 'I chart'
chart2 <- 'MR chart'
}
## Chart caption
if(SHOW_CAPTION) {
captn1 <- list(
text = paste0('<i>', chart1, '</i>'),
showarrow = F,
xref = 'paper',
x = 0,
yref = 'paper',
y = 1.05
)
captn2 <- list(
text = paste0('<i>', chart2, '</i>'),
showarrow = F,
xref = 'paper',
x = 0,
yref = 'paper',
y = 1.05
)
} else {
captn1 <- list()
captn2 <- list()
}
## Plot s chart or MR chart
pl <- pl %>%
add_trace(
x = df$sg,
y = df$mean_s,
text = ~paste0('Mean: ', sprintf(DECIMAL_FORMAT, df$mean_s)),
visible = F,
showlegend = F,
name = 'SPC'
) %>%
add_trace(
x = df$sg,
y = df$ucl_s,
text = paste0(chart2, '\nUCL +', CL_MULTIPLIER, ' sigma'),
visible = F,
showlegend = F
) %>%
add_trace(
x = df$sg,
y = df$lcl_s,
text = paste0(chart2, '\nLCL -', CL_MULTIPLIER, ' sigma'),
visible = F,
showlegend = F
) %>%
add_trace(
x = df$sg,
y = df$rate_s,
line = list(color = PRIMARY_COLOR),
text = ~paste0(
df$subgroup_row,
'\nRate: ',
sprintf(DECIMAL_FORMAT, df$rate_s)),
visible = F,
showlegend = F,
name = 'Rate'
)
## Create buttons to choose chart
btns <- list(
list(
active = 0,
type = 'buttons',
xanchor = 'left',
yanchor = 'bottom',
y = 0,
x = 1.02,
buttons = list(
list(
method = 'update',
label = paste0('<i>',chart1,'</i>'),
args = list(
list(visible = c(T, T, T, T, F, F, F, F)),
list(annotations = list(captn1, c())))),
list(
method = 'update',
label = paste0('<i>',chart2,'</i>'),
args = list(
list(visible = c(F, F, F, F, T, T, T, T)),
list(annotations = list(c(), captn2))))
)
)
)
return(list(pl, btns))
}