删除ggplot2中的负绘图区域

Eli*_*eth 7 plot r ggplot2

如何在ggplot2中删除x和y轴下方的绘图区域(参见下面的示例).我已经尝试了几个主题元素(panel.border,panel.margin,plot.margin)没有任何运气.

p <- ggplot(mtcars, aes(x = wt, y = mpg,xmin=0,ymin=0)) + geom_point()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Sim*_*lon 9

expand在连续尺度美学中使用这个论点......

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) )
Run Code Online (Sandbox Code Playgroud)

设置限制以避免极端值被切断. 在此输入图像描述

但如果您想在整个绘图周围没有边距,则需要使用该theme元素plot.margin,就像这样(在极右边缘下方的图中注意切割为零).

require(grid) # for unit
p + theme( plot.margin = unit( c(0,0,0,0) , "in" ) )
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • @ Simon0101,如果这就是答案,那么我将投票将这个问题作为[此]的副本结束(http://stackoverflow.com/questions/13701347/force-the-origin-to-start-at -0-in-ggplot2-r)特别是因为另一个问题比"删除负面情节区域"更明确....还在等待OP澄清虽然...... (2认同)