4.22 Output
print()
: Render it on screen (inside a loop or function, you’ll need to do it yourself)ggsave()
: Save it to disksaveRDS()
: Save a cached copy of it to disk- Saves complete copy of plot object (you can easily recreate it)
- Use
walk()
in combination withggsave()
to store several formats
# data_twitter_influence.csv
data <- read_csv(sprintf("https://docs.google.com/uc?id=%s&export=download",
"1dLSTUJ5KA-BmAdS-CHmmxzqDFm2xVfv6"),
col_types = cols())
p <- ggplot(data,
aes(x = followers_count,
y = n_retweets,
colour = party)) +
geom_point()
print(p)
ggsave("www/images/plot.png",width =5,height=5)
saveRDS(p, "www/images/plot.rds")
q <- readRDS("www/images/plot.rds")
walk(c('pdf', 'eps', 'png'),
~ ggsave(filename = file.path(paste0("www/images/figure-in-different-formats.", .x)),
device = .x,
plot = p))
## Saving 7 x 5 in image
## Saving 7 x 5 in image
## Saving 7 x 5 in image