Frist, you need to install the library. Here we use the ggplot library. So, if you don’t have the library installed you can install it by:
#install.packages("ggplot2")
After installation complete you have to call the library:
library(ggplot2)
Then we need to have a data file and we gonna show it. Here, we take iris data file which contains some plant information.
plant <- iris
head(plant)
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3.0 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 5 5.0 3.6 1.4 0.2 setosa
## 6 5.4 3.9 1.7 0.4 setosa
This diagram shows that Sepal length vs Petal width relation based on petal width and grouped by the species.
ggplot(plant) +
aes(x = Sepal.Length, y = Petal.Width, colour = Petal.Width, size = Petal.Width) +
geom_point(shape = "circle") +
scale_color_viridis_c(option = "plasma", direction = 1) +
theme_light() +
facet_wrap(vars(Species))
This is histogram representation of the Sepal length vs Petal length data based on the species.
ggplot(plant) +
aes(x = Sepal.Length,
y = Petal.Length,
fill = Species,
group = Petal.Width) +
geom_tile(size = 1.5) +
scale_fill_hue(direction = 1) +
theme_minimal()
Besides this, many kind of representaion can be done by ggplot pacakage.