I want to build a tiff
file with text only and no margins around the text, using R
.
I tried :
library(ggplot2)
plt <- ggplot() +
geom_text(aes(x=0,y=0,label="test")) +
theme_void()
ggsave(plt,filename="test.tif",bg="transparent")
However, there are large margins (I have added the borderline to highlight these margins):
What I want to get is a file with the image of the text, without any margin:
Is there a way to create such a tiff file, using ggplot, plot or any other R function?
This is pretty close, in base R: thanks to @r2evans for code to auto-adjust the width/height of the image:
txt <- "hello world"
dev.new()
tiff("test.tiff", strwidth(txt, units="in"),
strheight(txt, units="in"), units="in", res=300)
par(mar = rep(0,4))
plot(0:1, 0:1, type = "n", ann = FALSE, axes=FALSE)
text(0.5, 0.5, txt)
dev.off()