如何删除绘图区域周围的所有空间?
样本数据
dfr <- data.frame(x=factor(1:5),y=c(3,5,4,2,4))
ggplot(dfr,aes(x,y))+
geom_bar(stat="identity")
Run Code Online (Sandbox Code Playgroud)
我尝试如下,但左侧和底部仍然有空间。添加了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"))
Run Code Online (Sandbox Code Playgroud)
您需要添加axis.title=element_blank()到theme语句中。