r - 使用ggsave时遇到 "Error: $ operator is invalid for


这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这个问题的解决方式不太可能帮助 future 的读者。

关闭 1 年前

Improve this question

下面是我准备的代码作为示例。在我运行 ggsave 之前一切都很好。错误是关于 $ 运算符的,这很令人困惑。我见过很多人在不同的情况下都有类似的错误信息。是我的错还是内部 R 错误?

library(tidyverse)

xx <- seq(0,2,0.01); yy <- seq(0,2,0.02); zz <- seq(0,2,0.04)

dat <- data.frame(
  times = c(xx, yy, zz),
  val = c(sin(xx), sin(yy)+rnorm(length(yy),sd=0.2), sin(zz)+rnorm(length(zz),sd=0.3)),
  method = c(rep("A", length(xx)), rep("B", length(yy)), rep("C", length(zz)))
)

fig <- ggplot(dat) +
  geom_line(aes(x = times, y = val, col = method, linetype = method)) + 
  theme_minimal() +
  scale_color_manual(values = c("#29BDCE", "#ED8534", "#625559")) +
  scale_linetype_manual(values=c("solid", "longdash", "dashed")) +
  theme(legend.title = element_blank(),
        legend.position = "none") 

ggsave(fig, "D:/ResearchesAndProjects/2021_2_ODEadditive/code-ode-additive/examples/plots/test.png",
       device = "png", type ="cairo")
#> Saving 7 x 5 in image
#> Error: $ operator is invalid for atomic vectors
Created on 2021-07-01 by the reprex package (v2.0.0)

相关文章:

javascript - Js 文件作为 cypress 中的夹具未加载

rust - 为什么 Rust 中原始类型之间没有隐式类型转换(强制转换)

html - Bootstrap 警报按钮设计已关闭,单击时不会关闭

javascript - 两个 TX 的双哈希

postgresql - 使用 SymmetricDS 的主动-主动 PostgreSQL 配置

flutter - 未处理的异常 : type '_InternalLinkedHashMap

javascript - TypeScript 和文件上传类型

java - 在 JPA 存储库中连接两个表

algorithm - 如果一个节点等于二叉搜索树中的父节点,我们将它放在哪一边

python - Jinja2模板,去掉回车