Today, the main topic is data visualization, which means making a graph. It is important to create a graph in exploring, understanding, and summarizing data, finally going ahead to the publication. Various forms of graph are used to represent their data. The widely used forms of graphing include a scatter plot, histogram, boxplot, qqplot, and so on.
R is often known as their powerfulness in making a graph. The base R program includes graphics package which allows users to create and manipulate their own graph. Also, additional packages such as lattice or ggplot2 are built for the graphic purpose. In this chapter, I will decribe the basic use of graphic package , and I will introduce some examples of ggplot2 package with our experiment in a numerical task.
Graphics package is installed when you install the base program of R. The useful functions are listed as follows:
plot(x, y) : Create a scatter plot with x and y
plot(iris$Sepal.Length, iris$Sepal.Width)
plot(cars,
main = "CARS DATASET",
xlab = "SPEED OF CAR",
ylab = "STOPPING DISTANCE OF CAR")
plot(iris$Sepal.Length, iris$Sepal.Width, pch = as.integer(iris$Species))
plot(pressure, type = 'o')
abline() : Add line to the existing plot
m <- lm(Petal.Length ~ Petal.Width, data=iris)
with(iris, plot(Petal.Width, Petal.Length))
abline(m)
hist(): Add histogram
hist(sunspots, prob = T)
boxplot(): Add boxplot
boxplot(count ~ spray, data = InsectSprays, col = "lightgray")
please download the r script
Here are links of references:
Please download the data csv file and R script
Here are links of references: