The reason pdf("myplot.pdf") outputs an empty plot is that it is only activating the PDF graphics device to create a new empty file called "myplot.pdf", but it is not producing any actual content to be saved in the PDF file. You need to first create a plot by specifying the data to be plotted and the type of plot you want to create using one of the plotting functions in R (e.g. plot(), ggplot()). Once you have created the plot, you can then use pdf() to save it to a PDF file.
Here is an example:
```{r}
x <- 1:10 y <- x^2 plot(x, y, main = "My Plot")
pdf("my_plot.pdf") plot(x, y, main = "My Plot") # this is optional, but it will ensure that the plot is saved correctly dev.off() # this will close the PDF graphics device and save the file ```
In this example, we first create a plot using the plot() function, and then use pdf() to save it to a PDF file called "my_plot.pdf". The dev.off() function is called to close the PDF graphics device and ensure that the file is saved correctly.
Asked: 2021-12-31 11:00:00 +0000
Seen: 21 times
Last updated: Aug 04 '21