gpt4 book ai didi

删除 ggplot2 中的负绘图区域

转载 作者:行者123 更新时间:2023-12-04 11:25:53 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Force the origin to start at 0

(3 个回答)


8年前关闭。




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

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

enter image description here

最佳答案

使用 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) )

设置限制以避免极端值被截断。
enter image description here

但是如果您不希望整个图周围没有边距,则需要使用 theme元素, plot.margin ,像这样(注意在最右边缘下方的图中被削减为零)..
require(grid) # for unit
p + theme( plot.margin = unit( c(0,0,0,0) , "in" ) )

enter image description here

关于删除 ggplot2 中的负绘图区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18251701/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com