【问题标题】:Updating ggplot2 code for new version为新版本更新 ggplot2 代码
【发布时间】:2012-10-30 21:52:52
【问题描述】:

自从安装最新版本的 ggplot2 (0.9.1) 以来,我一直从我的旧代码中收到消息,包括:

> warnings()
Warning messages:
1: 'opts' is deprecated.
Use 'theme' instead.
See help("Deprecated")
2: 'theme_text' is deprecated.
Use 'element_text' instead.
See help("Deprecated")
8: In opts(title = trait axis.text.x = theme_text(size = fontsize$axis),  ... :
  Setting the plot title with opts(title="...") is deprecated. Use labs(title="...") or ggtitle("...") instead.
9: 'opts' is deprecated.

我有几个问题:

  1. help("Depreciated") 返回"no documentation for 'Depreciated' in specified packages and libraries";这是一个错误吗?
  2. 是否有一段时间“Depreciated”会变成“Obsolete”并且我的代码会开始抛出错误?
  3. 如何更新我的代码(以解决这些特定问题并防止其他人仍在等待被发现)?
  4. 我可以加载两个版本的 ggplot2 并指定我使用的每个函数的版本吗?
  5. 更新的语法在什么时间尺度上可能会过时?

我承认这是软件的常见问题,但也许 SO 的一些贡献者对软件包作者的长期计划和基本原理有具体的见解。

【问题讨论】:

  • CRAN 上的当前版本是 0.9.2.1,而不是 0.9.1。 @joran 对过渡指南的建议是有效的,但在 theme 设置方面对 0.9.2 有一些更改
  • @mnel 感谢您指出正确的当前版本!
  • joran 的回答 +1。这基本上是要走的路。话虽如此,ggplot 在这里有更好的警告信息之一。试着按照警告的建议去做。使用主题而不是选择。对我来说,它开箱即用。啊,你可能想在推特上关注@hadleywickham...
  • 请注意,它应该是 help("Deprecated"),而不是您一贯写的“Depreciated”。并不是说帮助文件在这里有很大帮助...

标签: r ggplot2


【解决方案1】:

来自Winston's github wiki,主要变化是:

  1. theme_xx() 函数更改为 element_xx()

    theme_segment() 并入theme_line()

  2. opts()改为theme()

  3. opts(title = "mytitle")改为labs(title = "mytitle")

  4. 使编程更容易的新功能,例如ggtitle("mytitle") 和 #3 一样

这是diff of some functions that I updated:

【讨论】:

    【解决方案2】:

    对于其中许多事情,我会开始关注ggplot2-dev mailing list 和/或包github repository

    您没有找到任何东西的原因仅仅是因为您拼错了“deprecated”。

    要升级您的代码,请参阅此transition guidethis one。我的理解是弃用是完全删除的第一步,这通常会在下一个“主要”版本中发生。由于 0.9.2 刚刚发布,我猜下一个至少需要 6-8 个月,但这只是猜测。

    加载不同版本的包是possible

    (小点:最新版本是0.9.2.1!)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-18
      • 1970-01-01
      • 1970-01-01
      • 2019-11-01
      • 2019-05-30
      • 1970-01-01
      • 2021-10-22
      • 2020-09-21
      相关资源
      最近更新 更多