- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我正在处理的数据集,来自链接:https://worldhappiness.report/ed/2022/文件名:Data_for_Figure_2.1
我试图找出变量在相关图中的相关性,代码如下所示
corr <- cor(happy22[, 3:8], method = "pearson")
ggplot(melt(corr, varnames = c("x", "y"), value.name = "correlation"),
aes(x = x, y = y)) +
geom_tile(aes(fill = correlation)) +
scale_fill_gradient2(
low = "green",
mid = "yellow",
high = "red",
guide = guide_colorbar(ticks = FALSE, barheight = 5),
limits = c(-1, 1)
) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(title = "Heatmap of correlation matrix",
x = NULL, y = NULL)
错误显示:
Error in FUN(X[[i]], ...) : object 'correlation' not found
In addition: Warning messages:
1: In type.convert.default(X[[i]], ...) :
'as.is' should be specified by the caller; using TRUE
2: In type.convert.default(X[[i]], ...) :
'as.is' should be specified by the caller; using TRUE
我不明白这是什么意思,为什么找不到“相关性”?我的代码中的“as.is”在哪里?
有人可以帮忙吗?
最佳答案
当我在包 reshape 中使用 melt()
时,我设法重现了您的错误。几年前,Just FYI reshape 已被 tidyverse 软件包套件所取代,我强烈建议切换到 ( https://www.tidyverse.org/packages/ )。在 tidyverse 中,您将使用函数 pivot_longer()
而不是 melt()
。
如果你单独运行 melt(corr, varnames = c("x", "y"), value.name = "correlation")
,你会发现没有结果名为 correlation
的列,这就是 ggplot
无法找到它的原因。 value.name
参数来自 reshape2,它取代了您使用的包。因此,您可以手动重命名第 3 列,切换到 reshape2 中的 melt
或切换到我推荐的 tidyverse。这是使用 tidyverse 中的 pivot_longer()
的相同逻辑:
library(tidyverse)
corr <- cor(happy22[, 3:8], method = "pearson",
use = "complete.obs")
corr %>%
as.data.frame() %>%
rownames_to_column('x') %>%
pivot_longer(-x,
names_to = 'y',
values_to = 'correlation') %>%
ggplot(.,
aes(x = x, y = y)) +
geom_tile(aes(fill = correlation)) +
scale_fill_gradient2(
low = "green",
mid = "yellow",
high = "red",
guide = guide_colorbar(ticks = FALSE, barheight = 5),
limits = c(-1, 1)
) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(title = "Heatmap of correlation matrix",
x = NULL, y = NULL)
关于r - 在 r 的聚类分析中找不到相关性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73008138/
我有一个如下所示的数据框: Samples GENE GEN1 GEN2 GEN3 GEN4 GEN5 Sample1 21.0 160 110 3.90 2.62 16.5 Sa
我有以下映射 posts":{ "properties":{ "prop1": { "type": "nested", "properties": { "item
我有两个维度相等的矩阵(p 和 e),我想在同名的列之间建立斯 PIL 曼相关。我想在矩阵 (M) 中输出对相关性 我使用了 Psych 库中的 corr.test() 函数,这是我所做的: libr
我有两个维度相等的矩阵(p 和 e),我想在同名的列之间建立斯 PIL 曼相关。我想在矩阵 (M) 中输出对相关性 我使用了 Psych 库中的 corr.test() 函数,这是我所做的: libr
我正在尝试使用 estpost 和 community-contributed 命令将 Spearman 相关矩阵导出到 rtf 或 Excel 文件中 esttab。 但是,我收到以下错误: inv
我在网上找到了以下查询: SELECT company_title FROM companies WHERE company_title like '%gge%' GROUP BY compa
我是 Sphinx 和 Lucene 的重度用户。Sphinx 只需要一个数据库,对其进行索引。然后您调用 Sphinx 获取 ID。 但是,如果我想创建一个非常微型 的搜索引擎怎么办?就几行数据,几
是否有我要在下面描述的模式/算法的名称?... 假设您有一棵像这样的相关数据树: IDEs Visual Studio Visual Studio 2008 Visual Studio 2010 Ec
早上好。这是我的问题:我有几个文件,如下所示: 104 0.1697 12.3513214 15.9136214 112 -0.3146 12.0517303 14.8027303 122 0.271
在尝试将function_score与boost_mode: "sum"一起使用时(因为这样可以更轻松地跟踪不同的贡献),我想归一化查询相关性对整体文档分数的影响,但是为此,我需要知道它可以取什么值。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
X,Y 的 spearmanr(Spearman 相关性)输出为我提供以下信息: 相关性:0.54542821980327882 P 值:2.3569040685361066e-65 其中 len(X
我有一个 Pandas 数据框,它有一个七年时间范围内的日期时间索引和 10 种不同 Assets 的价格数据。我想运行 dataframe.corr 函数来评估 Assets 之间的关系,我的问题是
我有相同数据(公司)的 2 个信息源,我可以通过唯一 ID(契约(Contract)号)将它们连接在一起。第二个不同来源的存在是由于这两个来源是手动独立更新的。所以我在 2 个表中有一个 ID 和一个
我正在尝试在php中实现两组数据之间人员相关系数的计算。我只是想做可以在这个 url 上找到的移植 python 脚本 http://answers.oreilly.com/topic/1066-ho
所以我使用 PHP Symfony 和 Ongr-Elasticsearch 包来查询我的文档并返回匹配的对象。结果似乎按相关性/分数排序,但实际相关性/分数不包含在对象本身中。 这可能吗?我想将分数
我想使用滚动窗口计算 DataFrame 两列之间的 Spearman 和/或 Pearson 相关性。 我试过df['corr'] = df['col1'].rolling(P).corr(df['
我正在处理一个大型数据集。不过,我将从一个小示例开始,以说明我要实现的目标。 我有以下向量: season %group_by(season, round, team)%>%dplyr::mutate
我正在使用 OIDC 的混合身份验证流程。 options.Events.OnRedirectToIdentityProvider = redirectContext =>
我正在尝试查询我的产品ElasticSearch索引并创建一个script_score,但我一直收到错误Variable [relevancy] is not defined. 我尝试只用一个数字替换
我是一名优秀的程序员,十分优秀!