gpt4 book ai didi

r - 相关性的错误视觉图表示

转载 作者:行者123 更新时间:2023-12-03 19:15:19 27 4
gpt4 key购买 nike

我构建了这段代码来检查比特币和其他 altCoin 之间的相关性,表格数据工作正常,我唯一的问题是当我尝试绘制结果以获得视觉表示时,我得到以下结果:

library(tidyverse)
library(tidyquant)
library(timetk)
library(tibbletime)
library(corrr)

symbols <- c("BTC-USD","ETH-USD","TRX-USD","EOS-USD","ADA-USD")

prices <- getSymbols(symbols,
src = 'yahoo',
from = "2019-09-01",
to = "2020-03-24",
auto.assign = TRUE,
warnings = FALSE) %>%
map(~Ad(get(.))) %>%
reduce(merge) %>%
`colnames<-`(symbols)

prices_monthly <- to.monthly(prices, indexAt = "last", OHLC = FALSE)

prices_monthly %>% correlate() %>% focus('BTC-USD') %>%
ggplot(aes(x = rowname, y = 'BTC-USD')) +
geom_bar(stat = "identity") +
ylab("Correlation with BTC-USD") +
xlab("Variable")

Plot result

请问我做错了什么?

最佳答案

您需要在变量名称周围加上反引号。

prices_monthly %>% correlate() %>% focus('BTC-USD') %>%
ggplot(aes(x = rowname, y=`BTC-USD`)) + # <- Here
geom_bar(stat="identity") +
ylab("Correlation with BTC-USD") +
xlab("Variable")

enter image description here

关于r - 相关性的错误视觉图表示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60897574/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com