-
Notifications
You must be signed in to change notification settings - Fork 0
/
boxplot.r
executable file
·43 lines (33 loc) · 1.02 KB
/
boxplot.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
#!/usr/bin/env Rscript
source("common.r")
## source:
## https://www.tutorialspoint.com/r/r_boxplots.htm
fn <- file.path(IMG.DIR,"boxplot.png")
## Give the chart file a name.
png(file = fn)
## Plot the chart.
boxplot(mpg ~ cyl, data = mtcars, xlab = "Number of Cylinders",
ylab = "Miles Per Gallon", main = "Mileage Data")
## Save the file.
dev.off()
cat("First plot has been written to:",fn,"\n")
## some further ideas:
## boxplot(mpg ~ gear, data=mtcars, varwidth=T)
## boxplot(mpg ~ am, data=mtcars, names=c("automatic","manual"))
## boxplot(mpg ~ vs, data=mtcars, names=c("V-Shaped","Linear"))
## Give the chart file a name.
fn <- file.path(IMG.DIR,"boxplot_with_notch.png")
png(file = fn)
# Plot the chart.
boxplot(mpg ~ cyl, data = mtcars,
xlab = "Number of Cylinders",
ylab = "Miles Per Gallon",
main = "Mileage Data",
notch = TRUE,
varwidth = TRUE,
col = c("green","yellow","purple"),
names = c("High","Medium","Low")
)
# Save the file.
dev.off()
cat("Second plot has been written to:",fn,"\n")