Faceting is one of the elements of ggplot package in R which is used to split the graphs. The data from different sources can be difficult to understand in a single plot as shown below. Therefore, we need to represent the information with clarity.
![](https://static.wixstatic.com/media/56e222_35e9c1f427b34d6190d1e206051557ea~mv2.png/v1/fill/w_704,h_439,al_c,q_85,enc_auto/56e222_35e9c1f427b34d6190d1e206051557ea~mv2.png)
Faceting have two main functions
Facet_grid( )
Facet_wrap( )
1.Facet_grid( )
library("ggolot2")
library("dplyr")
COVID_19%>%
filter(location %in% c("China", "Pakistan", "Spain", "Italy", "Germany", "Belgium"))%>%
ggplot(aes(x= cases, y = deaths, color = location))+
geom_point(size = 1)+
facet_grid(.~location)+
xlab("Total Cases")+
ylab("Total Deaths")+
ggtitle("Covid-19 Statistics")
![](https://static.wixstatic.com/media/56e222_a189cbdd9d1c4d13b342a2ba2475bb1d~mv2.png/v1/fill/w_704,h_439,al_c,q_85,enc_auto/56e222_a189cbdd9d1c4d13b342a2ba2475bb1d~mv2.png)
2.Facet_wrap( )
library("ggolot2")
library("dplyr")
COVID_19%>%
filter(location %in% c("China", "Pakistan", "Spain", "Italy", "Germany", "Belgium"))%>%
ggplot(aes(x= cases, y = deaths, color = location))+
geom_point(size = 1)+
facet_wrap(.~location)+
xlab("Total Cases")+
ylab("Total Deaths")+
ggtitle("Covid-19 Statistics")
![](https://static.wixstatic.com/media/56e222_c37f74445de24a13b03be15a913dea2f~mv2.png/v1/fill/w_704,h_439,al_c,q_85,enc_auto/56e222_c37f74445de24a13b03be15a913dea2f~mv2.png)
Comments