0
0
R Programmingprogramming~5 mins

Saving plots (ggsave) in R Programming - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the ggsave() function in R?

ggsave() saves a plot created with ggplot2 to a file on your computer, like a PNG or PDF.

Click to reveal answer
beginner
Which argument in ggsave() specifies the filename and file type?

The filename argument sets the name and extension (like "plot.png") to decide the file type.

Click to reveal answer
beginner
How do you save the last plot you made using ggsave() without specifying the plot object?

If you don't give a plot to ggsave(), it saves the last plot you displayed.

Click to reveal answer
intermediate
What arguments control the size of the saved plot in ggsave()?

width and height set the size of the saved image, usually in inches.

Click to reveal answer
intermediate
Can ggsave() save plots in formats other than PNG? Name two.

Yes! It can save as PDF, JPEG, TIFF, SVG, and more, depending on the file extension you use.

Click to reveal answer
What happens if you call ggsave("myplot.pdf") without specifying a plot?
AIt opens a dialog to select a plot.
BIt throws an error because no plot is specified.
CIt saves an empty file.
DIt saves the last plot you created.
Which argument do you use to change the width of the saved plot in ggsave()?
Asize
Bwidth
Clength
Dscale
If you want to save a plot as a PNG file, what should the filename end with?
A.png
B.jpeg
C.pdf
D.txt
Which package must be loaded to use ggsave()?
Adplyr
Bshiny
Cggplot2
Dtidyr
What does ggsave("plot.svg", plot = myplot) do?
ASaves the plot object <code>myplot</code> as an SVG file.
BSaves the last plot as SVG.
CSaves the plot as a PNG file.
DThrows an error because SVG is not supported.
Explain how to save a ggplot as a PDF file with a custom width and height using ggsave().
Think about the filename and size arguments.
You got /5 concepts.
    Describe what happens if you call ggsave() without specifying a plot and how you can save a specific plot instead.
    Consider the default behavior and how to override it.
    You got /2 concepts.