top of page

Faceting in R studio

Writer's picture: Fortune FornaxFortune Fornax

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.



Faceting have two main functions

  1. Facet_grid( )

  2. 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")


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")







10 views0 comments

Recent Posts

See All

Comments


Post: Blog2_Post
bottom of page