是否可以使用拼接在“主”标题下方和情节标题上方添加图例?
library(ggplot2)
library(patchwork)
p1 <- ggplot(mtcars, aes(disp, wt, color = factor(gear))) +
geom_point() +
labs(title = "first plot title")
p2 <- ggplot(mtcars, aes(drat, qsec, color = factor(gear))) +
geom_point() +
labs(title = "second plot title")
(p1+p2) +
plot_layout(guides = "collect") +
plot_annotation(title = "main title") &
theme(legend.position = "top")
Run Code Online (Sandbox Code Playgroud)
我无法理解为什么使用getOption检索我手动设置的选项NULL在并行执行中返回foreach,而它正确返回其他选项:
library(foreach)
options(my_option = 1)
f <- function(option){
cl <- parallel::makeCluster(parallel::detectCores() - 1)
doParallel::registerDoParallel(cl)
on.exit(parallel::stopCluster(cl), add = TRUE)
on.exit(foreach::registerDoSEQ(), add = TRUE)
foreach(i = 1:3) %dopar% {getOption(option)}
}
Run Code Online (Sandbox Code Playgroud)
例子:
f("warn")
[[1]]
[1] 0
[[2]]
[1] 0
[[3]]
[1] 0
f("my_option")
[[1]]
NULL
[[2]]
NULL
[[3]]
NULL
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用.export参数,但如果可能的话,我想要不使用它的解决方案。
我已经使用官员包创建了 powerpoint 文件,我还想将它们保存为 R 中的 pdf(不想手动打开每个文件并将其另存为 pdf)。这可能吗?