Preface
Maybe these methods are quite useful when dealing with the “assignment for Statistics”. —— GGN_2015 from Jilin University
Auto Install Package – pacman
# "pacman" is a package which can install packages automatically when the required package is not found.
install.packages("pacman")
# After "pacman" is installed, use the following code to autoload library "qcc"
library(pacman)
p_load(qcc)
Histogram
Here is a simple method to plot a Histogram with no packages required.
# Use R language to create a histogram
d = c(62,68,69,80,68,79,83,70,74,73,74,75,80,77,80,83,73,79,100,93,92,101,87,96,99,94,102,95,90,98,86,93,91,90,95,97,87,89,100,93,92,98,101,97,102,91,87,110,106,118)
hist(d, xlab = "Temperature", col = "white", border = "black", breaks = seq(60, 120, 10), right = TRUE, main = "Histogram for Temperature")
xlab
set the title of X axis;col
set the color of bars in histogram;border
set the color of the border of bars;breaks
set the data range of each bar;- the left-most and right-most point must contain all the values in data set;
right = TRUE
to set data range of each bar as Left-Open& Right-Closed;main
set the title of the whole diagram.
Pareto Diagram
# Please make sure that package "pacman" is installed before you run this program.
library(pacman)
# if there is no "qcc", install and load, otherwise load directly.
p_load(qcc)
# data set vector "Waste" (ordered it yourself)
Wastes= c(75, 31, 22, 8)
# give names to each column of vector "Wastes"
names(Wastes) = c('Plastic', 'Irom', 'Clothes', 'Spares')
# plot a pareto diagram
pareto.chart(
Wastes,
ylab="Waste Amount", # left-side-label
col = "white", # set the color of bars
# cumperc = seq(0, 120, by = 5), # coordinate on the Right
ylab2 = "Acummulative Percentage", # right-side-label
main = "Perato Diagram" # Title of the
)
Scattered Diagram
x_data = c(2.62,2.875,2.32,3.215,3.44,3.46,3.57,3.19,3.15,3.44,3.44,4.07,3.73,3.78,5.25,5.424,5.345,2.2,1.615,1.835,2.465,3.52,3.435,3.84,3.845,1.935,2.14,1.513,3.17,2.77,3.57,2.78)
y_data = c(21,21,22.8,21.4,18.7,18.1,14.3,24.4,22.8,19.2,17.8,16.4,17.3,15.2,10.4,10.4,14.7,32.4,30.4,33.9,21.5,15.5,15.2,13.3,19.2,27.3,26,30.4,15.8,19.7,15,21.4)
plot(x_data, y_data, ylab = "y data", xlab = "x data", main = "Scattered Diagram", type = "p")
# Use least-squares-method to get the linear relationship and show it on screen
abline(lm(y_data ~ x_data))
type="p"
create a dot diagram;type="l"
create a broken line diagram;type="o"
create a broken line diagram with dots between lines.