删除ggplot2中的阴图区域 [英] Removing negative plot area in ggplot2

查看:132
本文介绍了删除ggplot2中的阴图区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何删除ggplot2中x和y轴下方的绘图区域(请参阅下面的示例)。

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.

但是如果你不想在整个图表中留下空白,你需要使用主题元素, plot.margin ,就像所以(注意在右下边的阴谋部分被切成零)。

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" ) )

这篇关于删除ggplot2中的阴图区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆