gpt4 book ai didi

R ggplot : Remove all space around plot

转载 作者:行者123 更新时间:2023-12-04 12:02:07 26 4
gpt4 key购买 nike

如何删除绘图区域周围的所有空间?

示例数据

dfr <- data.frame(x=factor(1:5),y=c(3,5,4,2,4))

ggplot(dfr,aes(x,y))+
geom_bar(stat="identity")

我试过如下,但左边和底部还有空间。添加 Bg 边框颜色以可视化边缘。

ggplot(dfr,aes(x,y))+
geom_bar(stat="identity")+
labs(x="",y="")+
theme(axis.ticks=element_blank(),
axis.text=element_blank(),
plot.background=element_rect(colour="steelblue"),
plot.margin=grid::unit(c(0,0,0,0),"cm"))

enter image description here

最佳答案

您需要将 axis.title=element_blank() 添加到您的 theme 语句中。

enter image description here

关于R ggplot : Remove all space around plot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43964241/

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