How can I remove the plot area below the x and y axis in ggplot2 (see example below). I have tried several of the theme elements (panel.border, panel.margin, plot.margin) without any luck.
p <- ggplot(mtcars, aes(x = wt, y = mpg,xmin=0,ymin=0)) + geom_point()
Use the expand
argument in continuous scale aesthetics...
p <- ggplot(mtcars, aes(x = wt, y = mpg,xmin=0,ymin=0)) +
geom_point()+
scale_x_continuous( expand = c(0,0) , limits = c(0,6) )+
scale_y_continuous( expand = c(0,0), limits = c(0,35) )
Set limits to avoid extreme values being cut off.
but in case you wanted no margin around the entire plot, you need to use the theme
element, plot.margin
, like so (notice in the plot below the extreme right edge is cut to zero)..
require(grid) # for unit
p + theme( plot.margin = unit( c(0,0,0,0) , "in" ) )
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