【问题标题】:GGally::ggpairs plot does not display correlation coefficientsGGally::ggpairs 图不显示相关系数
【发布时间】:2020-06-10 20:23:36
【问题描述】:

我试图理解为什么在传递命令 ggpairs(iris, mapping=ggplot2::aes(colour = Species)) 时没有显示具有相关系数的图

console output

这是它的样子: the plots displaying the correlation coefficient are not visible

如果我在绘图上执行检查元素,则 html 中的图像标签是:

<img id="img" width="100%" height="100%" style="display: inline;" src="http://127.0.0.1:27032/graphics/b7091da9-1a0a-4672-902e-7c844add4aa9.png">

我刚刚开始学习 R,因此这让我很困惑。我觉得这是语言环境的问题,所以我尝试通过

Sys.setlocale("LC_ALL", 'en_US.UTF-8')

尽管再次调用库,但没有任何改变。

这里有一些细节:

R version 4.0.1 (2020-06-06) running on Arch Linux x86_64 5.6.15-arch1-1

> Sys.getlocale()
[1] "LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=C;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C"

如果我没有提供足够的数据,我深表歉意。如果是这样的话,我会更新这个。

使用install.packages("GGally", type = 'source') 的输出更新帖子


> install.packages("GGally", type = 'source')
Installing package into ‘/home/mogad0n/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/GGally_2.0.0.tar.gz'
Content type 'application/x-gzip' length 1393325 bytes (1.3 MB)
==================================================
downloaded 1.3 MB

* installing *source* package ‘GGally’ ...
** package ‘GGally’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (GGally)

The downloaded source packages are in
    ‘/tmp/RtmpvIM27v/downloaded_packages’

【问题讨论】:

  • 我已经删除了软件包并重新启动了 R 并执行了 install.packages("GGally", type = 'source') 以及 ggplot2 的相同操作,但它仍然存在相同的问题。我没有看到任何提及package encoding: UTF-8。我正在使用GGally 的安装命令的输出更新我的帖子。
  • 嗨@mogad0n。不幸的是,我无法重现您的问题。在我的(Windows)机器上一切正常。从您发布的图片来看,我看起来像是字体问题,因为文本显示不正确。要检查这是否与 GGAlly 或更一般的问题测试有关,例如ggplot(data.frame(label = "corr:", corr = 1)) + geom_text(aes(x = factor(1), y = factor(1), label = paste(label, corr), color = label), family = "mono") + guides(color = FALSE) + theme_void()` 为您提供了一个简单的绘图,应该使用单色字体显示 corr: 1
  • @stefan 它不显示它。所以很可能是字体问题?如果是的话,我将如何解决这个问题。我稍微研究了一下,发现对 extrafontshowtext 等软件包的引用。但我不想在没有某种推理的情况下做随机的事情
  • 嗨@mogad0n。这就是我的猜测。 (; 嗯。不幸的是,我恐怕无法帮助你。我会尝试重新启动 R (总是一个好主意)。否则发布一个关于特定字体问题的新问题,例如Fonts not displayed in ggplot2

标签: r ggplot2 ggally iris-dataset


【解决方案1】:

这显然与在 linux 中渲染等宽字体时的冲突有关——冲突似乎与 tex 有关(请参阅 herehere)。
这是之前的样子:

library(GGally)
iris %>% 
  select(Sepal.Length:Petal.Width) %>% 
  ggpairs()

输出:

在我告诉它使用sans 字体之后:

iris %>% 
  select(Sepal.Length:Petal.Width) %>% 
  ggpairs(upper = list(continuous = wrap("cor", family="sans")))

输出:

在 Ubuntu 20.04 和 R 版本 4.0.2 上为我工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-21
    • 1970-01-01
    • 2015-05-06
    • 2015-04-10
    • 1970-01-01
    • 2015-08-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多