Create a figure

p1 <- penguins |> na.omit() |>
  ggplot(aes(bill_depth_mm, 
             bill_length_mm,
             color = species,
             shape = island)) +
  geom_point()
p1

Create files in different formats and sizes

Focus on creating files separate from the Rmd or HTML output.

Bitmapped images

ggsave("penguins-2022-11-24.png", p1,
       dpi = 300, 
       width = 16, height = 10, units = "cm")
ggsave("penguins-small-2022-11-24.png", p1,
       dpi = 300, 
       width = 8, height = 5, units = "cm")
ggsave("penguins-small-2022-11-24.jpg", p1,
       dpi = 100, 
       width = 10, height = 6, units = "cm")

Vector images

ggsave("penguins-2022-11-24.pdf", p1,
       width = 16, height = 10, units = "cm")
ggsave("penguins-small-2022-11-24.pdf", p1,
       width = 8, height = 5, units = "cm")
ggsave("penguins-small-2022-11-24.svg", p1,
       width = 10, height = 6, units = "cm") # open with web browser

Formatting graphics in the Rmd output

Normal figure, not altered in any way.

p1

Custom height (4 inches), width (8 inches). (What does this mean on the screen?)

p1

You won’t see a change in Rstudio, but you will see a change in the webpage (HTML) output.

Output width 50% of “page”, centred left to right.

p1

SVG output (size changes when you zoom in the browser), Aspect ratio 1.4, width = 5 (inches)

p1