Removing negative graph area in ggplot2

How to remove the chart area below the x and y axis in ggplot2 (see example below). I tried several theme elements (panel.border, panel.margin, plot.margin) with no luck.

p <- ggplot(mtcars, aes(x = wt, y = mpg,xmin=0,ymin=0)) + geom_point() 

enter image description here

+7
r plot ggplot2
source share
1 answer

Use the expand argument in aesthetics of continuous scale ...

 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 exclude extreme values. enter image description here

but if you donโ€™t need a marker for the whole chart, you need to use the theme element, plot.margin , for example (the notification on the chart below the far right edge is cut to zero).

 require(grid) # for unit p + theme( plot.margin = unit( c(0,0,0,0) , "in" ) ) 

enter image description here

+9
source share

All Articles