简体   繁体   中英

here + ggplot2 particularly ggsave

I have been trying to clean up my project workflow, and have been using the here package, but have am perplexed at some of the utility.

I set up an Rstudio project in the folder ~\\ProjFolder. Within this folder I added a Plots folder ~\\ProjFolder\\Plots.

But when I try to use ggsave to save a plot into the Plots folder it instead places it in the ProjFolder.

library(here)
library(ggplot2)
xdat = rnorm(10)
ydat = rnorm(10)
df = data.frame(xdat,ydat)
ggplot(data = df, aes(x = xdat, y = ydat)) + geom_point()
here("Plots", ggsave("ScatterPlot.jpg"))

Any help? Or am I just using the here package ineffectively?

You should do ggsave(here("Plots", "ScatterPlot.jpg")) . here::here is just a way to provide the right file path, you put it in as a replacement for the path argument in functions that take one.

The problem is that you are composing here() and ggsave() in the wrong order. You want the first argument to ggsave() to be the full path, so

ggsave(here("Plots", "ScatterPlot.jpg"))

Does what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM