我怎样才能去除我的.png周围的奇怪的白边(用r,ggplot绘制)? [英] How can I remove the strange white margin around my .png (plotted with r, ggplot)?
本文介绍了我怎样才能去除我的.png周围的奇怪的白边(用r,ggplot绘制)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将ggplot的地块保存为.png。背景必须是黑色的,但总是有一个小的白色边缘(只有顶部,左边;不是右边)。
I save plots with ggplot as .png. The background has to be black, but there is allways a small white margin (only top, down an left; not right).
如何删除此保证金?
谢谢!
这是我的代码
Here is my Code
library(ggplot2)
require(grid)
dat <- data.frame("xvar"=runif(500, 1, 10),
"yvar"=runif(500, 1, 10))
n <- 1
for(i in 1:n){
png(file=paste("green", i, ".png", sep=""), width=400, height=400)
x <- sample(500, 50)
i <- ggplot(data=dat[x,], aes(x=xvar, y=yvar))+
geom_point(col="green", size=3,shape=15)+
theme(panel.background=element_rect(fill="black"), panel.grid.minor=element_blank(),
panel.grid.major=element_blank(), axis.text.x=element_blank(), axis.text.y=
element_blank(), axis.title.x=element_blank(), axis.title.y=element_blank(),
axis.ticks=element_blank(), plot.background=element_rect(fill="black"),
panel.margin = unit(c(0,0,0,0), "cm"), plot.margin = unit(c(0,0,0,0), "cm"))+
scale_x_continuous()
print(i)
dev.off() }
推荐答案
您看到的行是默认的轮廓颜色 plot.background
矩形元素。您可以通过在主题()
调用中将颜色设置为NA来删除它:
The line you are seeing is the default outline colour of the plot.background
rectangle element. You can remove it by setting colour to NA in your theme()
call:
theme(plot.background=element_rect(fill="black", colour=NA))
这篇关于我怎样才能去除我的.png周围的奇怪的白边(用r,ggplot绘制)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文