[英]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. 我在〜\\ ProjFolder文件夹中设置了一个Rstudio项目。 Within this folder I added a Plots folder ~\\ProjFolder\\Plots.
在这个文件夹中,我添加了一个Plots文件夹〜\\ ProjFolder \\ Plots。
But when I try to use ggsave to save a plot into the Plots folder it instead places it in the ProjFolder. 但是当我尝试使用ggsave将绘图保存到Plots文件夹中时,它会将其放在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"))
. 你应该做
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. here::here
只是一种提供正确文件路径的方法,你把它放在作为一个的函数中的路径参数的替代。
The problem is that you are composing here()
and ggsave()
in the wrong order. 问题是你在错误的顺序组合
here()
和ggsave()
。 You want the first argument to ggsave()
to be the full path, so 你希望
ggsave()
的第一个参数成为完整路径,所以
ggsave(here("Plots", "ScatterPlot.jpg"))
Does what you want. 你想要的是什么
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.