Uses of facet_wrap and facet_grid



I am studying about plotting in R using ggplot while studying I came across two function name as facet_wrap and facet_grid.

Their syntax are
facet_wrap(~variable,ncol) ## the variable in which you split the plot
facet_grid(vertical ~ horizontal) the horizontal and vertical variable in which you split the plot.

I want to know where to use this function and how they are different.


hello @harry,

facet_wrap essentially splits your plot across the categories you want.
For example you want to see the scatter plot of income vs age across the four regions of India facet_wrap will split the plots across these categories.

Please go through for a detailed understanding.

facet_grid does a similar thing but instead of creating different plots it creates different grids and then plots each plot in the grids.

Hope this helps!!