1

I am trying to use dev.copy2eps() function to save my outputted charts. However, when I change the plot width and height in the function, all the strings (including labels and legend) do not appear.

Example of an outputted plot (with non-default sizes): enter image description here

Code:

boxplot(volunteers$number_of_commits, employees$number_of_commits, las = 1, outline = FALSE, cex.lab=1.2, horizontal = TRUE, margin = list(l = 10, r = 10, b = 0, t = 0), col=(c("#b8d1ed", "#aae0c0")), main = "Number of Commits")
legend("bottomright", legend=c("Employees", "Volunteers"), fill=c("#aae0c0", "#b8d1ed"), inset= .02, cex=1.1)
dev.copy2eps(file="Images/atom/atom_num_commits.eps", width = 650, height = 360)

The question is: How can I save my chart in different sizes using the postscript function, maintaining the same quality and information?

loki
  • 9,816
  • 7
  • 56
  • 82

1 Answers1

0

In short: your height and width parameters seem to be the problem.

It turns out that the labels are not removed if you add height and width BUT EXTREMELY SMALL. By removing these, you will be able to see the labels in the eps, or consider using significantly smaller values.

plot(cars$speed~cars$dist)
legend("bottomright", legend=c("Employees", "Volunteers"), fill=c("#aae0c0", "#b8d1ed"), inset= .02, cex=1.1)
dev.copy2eps(file = "your_path/test.eps")

The output of your EPS plot will have the same aspect ratio of height and width as you plotting device (in RGUI or RStudio). You can add the parameters to maintain aspect ratio, but reduce the magnitude of their values. Please see this section from ?dev.copy2eps:

If dev.print is used with a specified device (even postscript) it sets the width and height in the same way as dev.copy2eps. This will not be appropriate unless the device specifies dimensions in inches, in particular not for png, jpeg, tiff and bmp unless units = "inches" is specified.

Another solution, in which you can also directly adjust the width and height (in inches, so you might think of the magnitude) was proposed in s.brunel's comment:

setEPS()
postscript("C:/Users/weig_mi/Desktop/test2.eps", width = 6.5, height = 3.60)
plot(cars$speed~cars$dist)
legend("bottomright", legend=c("Employees", "Volunteers"), fill=c("#aae0c0", "#b8d1ed"), inset= .02, cex=1.1)
dev.off()

From ?postscript we learn that width and height are

the width and height of the graphics region in inches.

loki
  • 9,816
  • 7
  • 56
  • 82