I would like to use facet grid to display only the right margin not the bottom margin.
Example Code
library(ggplot2)
qplot(mpg, wt, data=mtcars) + facet_grid(cyl ~ vs, margins=TRUE)
Currently Outcome
Desired Outcome
The facet_grid() function will produce a grid of plots for each combination of variables that you specify, even if some plots are empty. The facet_wrap() function will only produce plots for the combinations of variables that have values, which means it won't produce any empty plots.
facet_grid() forms a matrix of panels defined by row and column faceting variables. It is most useful when you have two discrete variables, and all combinations of the variables exist in the data. If you have only one variable with many levels, try facet_wrap() .
You can use the following basic syntax to specify the order of facets in ggplot2: p + facet_grid(~factor(my_variable, levels=c('val1', 'val2', 'val3', ...))) The following example shows how to use this syntax in practice.
A FacetGrid is a multi-axes grid with subplots visualizing the distribution of variables of a dataset and the relationship between multiple variables.
qplot(mpg, wt, data=mtcars) + facet_grid(cyl ~ vs, margins="vs")
When this answer was written, this behavior was not documented. Now, it is in the facet_grid documentation
margins either a logical value or a character vector. Margins are additional facets which contain all the data for each of the possible values of the faceting variables. If
FALSE
, no additional facets are included (the default). IfTRUE
, margins are included for all faceting variables. If specified as a character vector, it is the names of variables for which margins are to be created.
(Thanks to @Harry for pointing this out.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With