我正在使用tikzDevice包来获取R. 我无法从下图的顶部和底部删除过多的空白:

我试过使用,par(mar)但它似乎不适用于ggplot2. 此外,theme(plot.margins)似乎也没有反应。当我尝试用 改变图形的纵横比时引入了空白theme(aspect.ratio)。有什么建议?谢谢!
编辑:这是一个 MWE:
library(tikzDevice)
library(reshape2)
x = seq(0,1,0.1)
y1 = x^2+2*x+7
y2= x^+2*x+2
df = data.frame(x,y1,y2)
df <- melt(df, id.vars=c("x"))
names(df) <- c("x","$latex~Name$","value")
plot <- ggplot(df,aes(x=x,y=value,color=`$latex~Name$`,group=`$latex~Name$`)) + geom_line() +
theme(aspect.ratio = 0.4)
plot
tikzDevice(file="mweTex.tex")
plot
dev.off()
Run Code Online (Sandbox Code Playgroud)
该问题似乎是由一些影响图像边界框的 tikz 语句引起的。由于 tikzDevice 中似乎没有任何选项可以最小化空格,因此我不得不考虑其他事情。我设法通过在 MWE 末尾添加以下 R 代码来修复生成的 tikz 文件:
# remove all lines that invisibly mess up the bounding box
lines <- readLines(con="mweTex.tex")
lines <- lines[-which(grepl("\\path\\[clip\\]*", lines,perl=F))]
lines <- lines[-which(grepl("\\path\\[use as bounding box*", lines,perl=F))]
writeLines(lines,con="mweTex.tex")
Run Code Online (Sandbox Code Playgroud)
我已经在你的 MWE 上测试过了:
| 归档时间: |
|
| 查看次数: |
688 次 |
| 最近记录: |