This question already has answers here:
Force the origin to start at 0
(2个答案)
6年前关闭。
如何在ggplot2中删除x和y轴下方的绘图区域(请参见下面的示例)。我尝试了几个主题元素(panel.border,panel.margin,plot.margin),但没有任何运气。
设置限制以避免极端值被切断。
但是如果您不希望整个图周围有空白,则需要使用
(2个答案)
6年前关闭。
如何在ggplot2中删除x和y轴下方的绘图区域(请参见下面的示例)。我尝试了几个主题元素(panel.border,panel.margin,plot.margin),但没有任何运气。
p <- ggplot(mtcars, aes(x = wt, y = mpg,xmin=0,ymin=0)) + geom_point()
最佳答案
在连续尺度美学中使用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) )
设置限制以避免极端值被切断。
但是如果您不希望整个图周围有空白,则需要使用
theme
元素plot.margin
,就像这样(在图的最右端以下的注意被切为零)。require(grid) # for unit
p + theme( plot.margin = unit( c(0,0,0,0) , "in" ) )
关于r - 删除ggplot2中的负图区域,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18251701/
10-12 20:48