I am trying to save a matplot as eps on R. So far all the instructions I have been able to find online were either for the matplotlib in Python or they were something along the lines of saving the graph by right clicking directly, or by using the lines of code:
jpeg("name.jpg")
matplot(t, r[,1:n], type="l", lty=1, ylab="",xlab="Year")
dev.off()
But the quality/resolution of these saved graphs are dreadful. I was hoping something similar to
setEPS()
postscript("name.eps")
matplot(t, r[,1:n], type="l", lty=1, ylab="",xlab="Year")
dev.off()
But unfortunately this does not seem to work for matplot.
CodePudding user response:
A jpeg file is a highly compressed file that loses information. It is never useful for graphics that will be printed or edited. In addition the default size and quality is small and low so you could have improved your results by printing a larger image at higher quality (see ?jpeg for details).
A postscript file (EPS) preserves the information lost by creating a jpeg file and stores the instructions for drawing the image, not a bitmap of the image. It is not clear what you problems were, but here is a simple example:
First, always provide reproducible data:
set.seed(42)
t <- 1950:1975
r1 <- rnorm(26, 35, 5)
r2 <- rnorm(26, 50, 5)
r3 <- rnorm(26, 65, 5)
r <- cbind(r1, r2, r3)
Now the plot:
setEPS()
postscript("name.eps")
matplot(t, r[, 1:3], type="l", lty=1, ylab="",xlab="Year")
dev.off()
readLines("name.eps", 10) # Check the results
# [1] "%!PS-Adobe-3.0" "%%DocumentNeededResources: font Helvetica" "%% font Helvetica-Bold"
# [4] "%% font Helvetica-Oblique" "%% font Helvetica-BoldOblique" "%% font Symbol"
# [7] "%%DocumentMedia: a4 595 841 0 () ()" "%%Title: R Graphics Output" "%%Creator: R Software"
# [10] "%%Pages: (atend)"