make_graphs <- function(df, explanatory, response, title_string, xlab_string, ylab_string, filename) {
formula_string <- paste(substitute(response), "~", substitute(explanatory))
# winner: https://win-vector.com/2019/07/06/programming-over-lm-in-r/
# https://stackoverflow.com/questions/27261232/passing-argument-to-lm-in-r-within-function
model <- eval(bquote( lm( as.formula(formula_string), data = df) ))
print(model)
# ggplot scatterplot without line
sp <- ggplot(df, aes( x = {{ explanatory }}, y = {{ response }} )) +
geom_point(size = 4) +
ggtitle( title_string ) +
xlab( xlab_string ) +
ylab( ylab_string ) +
theme_bw(base_size = 18)
print(sp) # generates both graph and VI(ts) automatically
# ggplot scatterplot with line
sp <- sp + geom_smooth(method='lm', se=FALSE, size=2, color = "black")
print(sp) # generates both graph and VI(ts) automatically
MakeAccessibleSVG.ggplot(sp, file = paste0("reader-", filename))
# tactile scatterplot with no line
brl_begin(paste0( 'tactile-', filename, '-scatterplot.pdf'),
pt=12, paper='special', font='SWL') #, font='BRL' or 'SWL')
# to get the variable values, use data[[substitute(varname)]] instead of data$varname
plot(df[[substitute(explanatory)]],
df[[substitute(response)]],
main = title_string,
xlab = xlab_string,
ylab = ylab_string
)
brl_end()
# tactile scatterplot with line
brl_begin(paste0( 'tactile-', filename, '-scatterplot-and-line.pdf'),
pt=12, paper='special', font='SWL') #, font='BRL' or 'SWL')
# to get the variable values, use data[[substitute(varname)]] instead of data$varname
plot(df[[substitute(explanatory)]],
df[[substitute(response)]],
main = title_string,
xlab = xlab_string,
ylab = ylab_string
)
abline( model, col = "black", lwd = 3 )
brl_end()
# tactile scatterplot with line and ellipses and boxplots
brl_begin(paste0( 'tactile-', filename, '-scatterplot-and-line-and-ellipses-and-boxplots.pdf'),
pt=12, paper='special', font='SWL') #, font='BRL' or 'SWL')
scatterplot( as.formula(formula_string), data = df,
main = title_string,
xlab = xlab_string,
ylab = ylab_string,
pch = 16, cex = 2, col = "black",
smooth = FALSE, grid = FALSE, frame = TRUE,
ellipse = list(levels=c(.25, .75), robust=TRUE, fill=FALSE, fill.alpha=0, lwd = 3) )
brl_end()
}
Piercings SkippedClasses
1 8 6
2 1 2
3 0 0
4 0 1
5 0 0
6 4 0
7 4 4
8 5 0
9 3 1
10 5 0
11 2 0
12 2 2
13 2 0
14 2 3
15 2 1
16 2 1
17 6 1
18 4 5
19 4 2
20 4 2
21 0 3
22 0 10
23 2 0
24 5 0
25 5 3
26 0 0
27 1 2
28 1 3
29 4 2
30 2 0
31 3 2
32 0 0
33 4 0
34 1 1
35 2 0
36 0 1
37 4 0
38 0 1
39 4 4
40 0 0
41 10 2
42 2 2
43 2 0
44 4 3
45 2 0
46 2 1
47 2 4
48 2 1
49 0 0
50 2 0
51 2 1
52 0 1
53 12 5
54 0 0
55 2 5
56 5 5
57 3 2
58 2 1
59 2 0
60 2 2
61 7 1
62 5 5
63 4 1
64 0 0
65 4 0
66 0 0
67 4 0
68 5 2
69 5 1
70 4 4
71 0 1
72 5 2
73 0 4
74 6 4
75 9 0
76 0 1
77 0 1
78 2 0
79 0 6
80 0 0
81 3 1
82 6 4
83 2 1
84 0 1
85 6 0
86 0 2
87 6 5
88 2 0
89 0 2
90 2 3
91 0 2
92 0 1
93 0 0
94 3 2
95 0 2
96 2 3
97 0 0
98 4 1
99 0 0
100 2 0
101 1 0
102 3 0
103 0 0
104 2 0
105 8 0
106 2 0
Call:
lm(formula = as.formula(formula_string), data = df)
Coefficients:
(Intercept) Piercings
1.098 0.165
This scatter plot has title ‘foot length versus height’ with x-axis ‘foot length (cm)’ that has values from 24 to 36 centimeters, and y-axis ‘height (in)’ with values from 55 to 80 inches. There are 20 big solid circle points. The points are somewhat spread out but do show a clear increase in height as foot length increases.
This chart has title 'HW 10.5 #1 piercings vs classes skipped'.
It has x-axis 'piercings' with labels 0.0, 2.5, 5.0, 7.5, 10.0 and 12.5.
It has y-axis 'classes skipped' with labels 0.0, 2.5, 5.0, 7.5 and 10.0.
The chart is a set of 106 big solid circle points of which about 39% can be seen.
It has size set to 4.
This chart has title 'HW 10.5 #1 piercings vs classes skipped'.
It has x-axis 'piercings' with labels 0.0, 2.5, 5.0, 7.5, 10.0 and 12.5.
It has y-axis 'classes skipped' with labels 0.0, 2.5, 5.0, 7.5 and 10.0.
It has 2 layers.
Layer 1 is a set of 106 big solid circle points of which about 39% can be seen.
Layer 1 has size set to 4.
Layer 2 is a 'lm' smoothed curve.Layer 2 has colour set to black.
Layer 2 has size set to 2.
This chart has title 'HW 10.5 #1 piercings vs classes skipped'.
It has x-axis 'piercings' with labels 0.0, 2.5, 5.0, 7.5, 10.0 and 12.5.
It has y-axis 'classes skipped' with labels 0.0, 2.5, 5.0, 7.5 and 10.0.
It has 2 layers.
Layer 1 is a set of 106 big solid circle points of which about 39% can be seen.
Layer 1 has size set to 4.
Layer 2 is a 'lm' smoothed curve.Layer 2 has colour set to black.
Layer 2 has size set to 2.
This scatter plot has title ‘foot length versus height’ with x-axis ‘foot length (cm)’ that has values from 24 to 36 centimeters, and y-axis ‘height (in)’ with values from 55 to 80 inches. There are 20 big solid circle points. The points are somewhat spread out but do show a clear increase in height as foot length increases.
png
2
tab <- table(piercings$Piercings, piercings$SkippedClasses)
t(tab)
0 1 2 3 4 5 6 7 8 9 10 12
0 14 1 14 1 5 3 1 0 1 1 0 0
1 9 1 7 2 2 1 1 1 0 0 0 0
2 4 2 3 3 3 2 0 0 0 0 1 0
3 1 1 3 0 1 1 0 0 0 0 0 0
4 1 0 1 0 3 0 2 0 0 0 0 0
5 0 0 1 0 1 2 1 0 0 0 0 1
6 1 0 0 0 0 0 0 0 1 0 0 0
10 1 0 0 0 0 0 0 0 0 0 0 0
#str(tbl)
#tbl[order(-as.numeric(names(tbl)))]
# Sort table by converting to DataFrame
df <- tab %>%
as.data.frame() %>%
arrange(desc(Freq))
names(df) <- c("Piercings","SkippedClasses","Frequency")
#df
sum(df$Frequency)
[1] 106
df <- df[ df$Frequency != 0, ]
print( df, row.names = FALSE )
Piercings SkippedClasses Frequency
0 0 14
2 0 14
0 1 9
2 1 7
4 0 5
0 2 4
5 0 3
2 2 3
3 2 3
4 2 3
2 3 3
4 4 3
3 1 2
4 1 2
1 2 2
5 2 2
6 4 2
5 5 2
1 0 1
3 0 1
6 0 1
8 0 1
9 0 1
1 1 1
5 1 1
6 1 1
7 1 1
10 2 1
0 3 1
1 3 1
4 3 1
5 3 1
0 4 1
2 4 1
2 5 1
4 5 1
6 5 1
12 5 1
0 6 1
8 6 1
0 10 1
df$Piercings <- as.numeric(df$Piercings)
df$SkippedClasses <- as.numeric(df$SkippedClasses)
# tactile scatter/frequency plot
brl_begin(paste0( 'tactile-HW_10.5.1-scatterfrequencyplot.pdf'),
pt=12, paper='special', font='SWL') #, font='BRL' or 'SWL')
plot( df$Piercings, df$SkippedClasses, type = "n")
text( df$Piercings, df$SkippedClasses, df$Frequency,
main = "HW 10.5 #1 piercings vs SkippedClasses",
xlab = "piercings",
ylab = "skipped classes"
)
brl_end()
png
2
#plot(as.numeric(df$Piercings), as.numeric(df$SkippedClasses))
DCQ AccuracyFace
1 2 43.1
2 6 44.2
3 7 41.0
4 14 46.2
5 17 51.1
6 20 48.3
7 1 57.1
8 0 59.2
9 0 60.1
10 1 61.1
11 2 60.2
12 2 62.1
13 5 59.2
14 6 62.1
15 5 63.2
16 4 63.2
17 4 64.1
18 4 66.1
19 3 66.0
20 2 65.0
21 1 63.2
22 1 64.0
23 1 65.0
24 1 66.0
25 1 67.1
26 0 72.0
27 0 79.9
28 3 71.0
29 4 71.1
30 4 73.2
31 5 72.1
32 6 72.1
33 7 66.0
34 8 67.1
35 8 71.0
36 8 73.1
37 10 66.2
38 10 70.2
39 11 68.1
40 11 70.2
41 11 71.0
42 11 74.2
43 11 75.1
44 12 75.1
45 12 72.2
46 12 67.2
47 13 66.2
48 14 65.1
49 15 64.3
50 14 68.1
51 13 71.1
52 14 73.0
53 16 69.3
54 16 73.0
55 21 71.1
56 18 75.2
57 17 78.2
58 16 78.2
59 15 78.1
60 15 75.2
61 17 81.1
62 17 82.2
63 16 85.2
64 17 89.0
65 18 75.2
66 11 68.1
67 3 66.1
68 13 66.2
69 21 71.1
70 1 63.2
71 1 64.0
72 8 67.1
73 1 64.0
74 11 68.1
Call:
lm(formula = as.formula(formula_string), data = df)
Coefficients:
(Intercept) DCQ
63.0 0.5
This scatter plot has title ‘foot length versus height’ with x-axis ‘foot length (cm)’ that has values from 24 to 36 centimeters, and y-axis ‘height (in)’ with values from 55 to 80 inches. There are 20 big solid circle points. The points are somewhat spread out but do show a clear increase in height as foot length increases.
This chart has title 'HW 10.5 #8 DCQ vs face accuracy'.
It has x-axis 'DCQ' with labels 0, 5, 10, 15 and 20.
It has y-axis 'face accuracy' with labels 40, 50, 60, 70, 80 and 90.
The chart is a set of 74 big solid circle points of which about 85% can be seen.
It has size set to 4.
This chart has title 'HW 10.5 #8 DCQ vs face accuracy'.
It has x-axis 'DCQ' with labels 0, 5, 10, 15 and 20.
It has y-axis 'face accuracy' with labels 40, 50, 60, 70, 80 and 90.
It has 2 layers.
Layer 1 is a set of 74 big solid circle points of which about 85% can be seen.
Layer 1 has size set to 4.
Layer 2 is a 'lm' smoothed curve.Layer 2 has colour set to black.
Layer 2 has size set to 2.
This chart has title 'HW 10.5 #8 DCQ vs face accuracy'.
It has x-axis 'DCQ' with labels 0, 5, 10, 15 and 20.
It has y-axis 'face accuracy' with labels 40, 50, 60, 70, 80 and 90.
It has 2 layers.
Layer 1 is a set of 74 big solid circle points of which about 86% can be seen.
Layer 1 has size set to 4.
Layer 2 is a 'lm' smoothed curve.Layer 2 has colour set to black.
Layer 2 has size set to 2.
This scatter plot has title ‘foot length versus height’ with x-axis ‘foot length (cm)’ that has values from 24 to 36 centimeters, and y-axis ‘height (in)’ with values from 55 to 80 inches. There are 20 big solid circle points. The points are somewhat spread out but do show a clear increase in height as foot length increases.
png
2
DCQ BodyAccuracy
1 4 50.8
2 17 51.7
3 1 58.9
4 2 58.9
5 4 58.9
6 4 61.9
7 4 62.9
8 2 62.9
9 1 62.9
10 1 61.9
11 1 60.9
12 0 61.9
13 6 62.9
14 5 62.9
15 11 63.8
16 12 63.8
17 15 64.8
18 16 65.8
19 17 68.8
20 21 68.7
21 14 67.8
22 14 68.9
23 13 68.9
24 12 67.9
25 12 66.9
26 11 66.8
27 10 65.8
28 11 68.8
29 8 66.8
30 7 67.9
31 5 66.8
32 4 67.8
33 2 65.9
34 5 67.8
35 4 68.9
36 3 69.9
37 3 67.9
38 2 67.9
39 1 67.8
40 1 66.9
41 0 66.9
42 0 67.9
43 0 69.8
44 1 73.9
45 0 76.9
46 4 70.9
47 6 73.0
48 6 70.9
49 8 69.8
50 8 68.9
51 10 72.9
52 11 71.9
53 11 69.9
54 15 69.8
55 16 69.8
56 16 70.8
57 16 71.8
58 17 70.7
59 17 73.7
60 20 71.8
61 15 75.9
62 14 75.8
63 13 74.8
64 12 75.9
65 1 79.9
66 17 79.8
67 18 79.9
68 2 65.9
69 5 66.8
70 20 71.8
71 17 70.7
72 0 61.9
73 11 68.8
74 7 67.9
Call:
lm(formula = as.formula(formula_string), data = df)
Coefficients:
(Intercept) DCQ
65.488 0.293
This scatter plot has title ‘foot length versus height’ with x-axis ‘foot length (cm)’ that has values from 24 to 36 centimeters, and y-axis ‘height (in)’ with values from 55 to 80 inches. There are 20 big solid circle points. The points are somewhat spread out but do show a clear increase in height as foot length increases.
This chart has title 'HW 10.5 #9 DCQ vs body accuracy'.
It has x-axis 'DCQ' with labels 0, 5, 10, 15 and 20.
It has y-axis 'body accuracy' with labels 50, 60, 70 and 80.
The chart is a set of 74 big solid circle points of which about 91% can be seen.
It has size set to 4.
This chart has title 'HW 10.5 #9 DCQ vs body accuracy'.
It has x-axis 'DCQ' with labels 0, 5, 10, 15 and 20.
It has y-axis 'body accuracy' with labels 50, 60, 70 and 80.
It has 2 layers.
Layer 1 is a set of 74 big solid circle points of which about 91% can be seen.
Layer 1 has size set to 4.
Layer 2 is a 'lm' smoothed curve.Layer 2 has colour set to black.
Layer 2 has size set to 2.
This chart has title 'HW 10.5 #9 DCQ vs body accuracy'.
It has x-axis 'DCQ' with labels 0, 5, 10, 15 and 20.
It has y-axis 'body accuracy' with labels 50, 60, 70 and 80.
It has 2 layers.
Layer 1 is a set of 74 big solid circle points of which about 91% can be seen.
Layer 1 has size set to 4.
Layer 2 is a 'lm' smoothed curve.Layer 2 has colour set to black.
Layer 2 has size set to 2.
This scatter plot has title ‘foot length versus height’ with x-axis ‘foot length (cm)’ that has values from 24 to 36 centimeters, and y-axis ‘height (in)’ with values from 55 to 80 inches. There are 20 big solid circle points. The points are somewhat spread out but do show a clear increase in height as foot length increases.
png
2