It is often desirable to minimize ink in a plot. I have a faceted plot (facet_wrap
) and would like to remove as much ink as possible yet maintain readability. I have set it up as I'd like except the x and y axis is not present for the facets (subplots) unless on the far left or bottom. With so much ink removed I believe the eye needs these cues and am asking how to put the x and y axis in all plots within a facet_wrap
. Below is my code thus far, the current output and the deired output (red lines are the desired add in):
library(ggplot); library(grid) ggplot(mtcars, aes(mpg, hp)) + geom_point() + facet_wrap(~carb) + theme(panel.grid = element_blank(), panel.background = element_rect(fill = "white", colour = "black"), panel.border = element_rect(fill = NA, colour = "white"), axis.line = element_line(), strip.background = element_blank(), panel.margin = unit(2, "lines"))
Current Plot
Desired Plot
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 labels can be modified using the option labeller , which should be a function. In the following R code, facets are labelled by combining the name of the grouping variable with group levels. The labeller function label_both is used.
To alter the labels on the axis, add the code +labs(y= "y axis name", x = "x axis name") to your line of basic ggplot code. Note: You can also use +labs(title = "Title") which is equivalent to ggtitle .
This should simplify things considerably:
library('ggthemes') ggplot(mtcars, aes(mpg, hp)) + geom_point() + facet_wrap(~carb, scales='free') + theme_tufte() + theme(axis.line=element_line()) + scale_x_continuous(limits=c(10,35)) + scale_y_continuous(limits=c(0,400))
easiest way would be to add segments in each plot panel,
ggplot(mtcars, aes(mpg, hp)) + geom_point() + facet_wrap(~carb) + theme_minimal() + annotate("segment", x=-Inf, xend=Inf, y=-Inf, yend=-Inf)+ annotate("segment", x=-Inf, xend=-Inf, y=-Inf, yend=Inf)
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