r - is.finite(x) 中的 ggplot 错误并且不知道如何选择比例
问题描述
我在 ggplot 中的散点图有问题。了解 ggplot 不喜欢列表中的数据,但是当我检查该类时,它是一个数据框。我得到的错误是
Dont know how to automatically pick scale for object of type data.frame. Defaulting to continuous.
Error in is.finite(x) : default method not implemented for type 'list'
我要散点图的数据是:
Risk Reward
NCM 0.02546471 0.0001596743
TLS 0.01288961 0.0002183247
CCL 0.01510990 0.0002710004
WOW 0.01270629 0.0002937180
MVF 0.02302660 -0.0002582542
代码
ggplot(riskreward, aes(x = risk, y = reward))+ geom_point()
如果它有效,它应该看起来像这样(在 excel 中创建 )
解决方案
我已按如下方式复制了您的数据框表(我假设您已经拥有它)
df <- data.frame(numeric(), numeric())
df <- rbind(df, c(0.02546471, 0.0001596743))
df <- rbind(df, c(0.01288961, 0.0002183247))
df <- rbind(df, c(0.01510990, 0.0002710004))
df <- rbind(df, c(0.01270629, 0.0002937180))
df <- rbind(df, c(0.02302660, -0.0002582542))
colnames(df) <- c("Risk", "Reward")
迄今为止绘制图形的最佳库是 ggplot2。它为您的绘图提供了广泛的自定义选项。
因此,您可以导入 ggplot2 并运行以下代码:
ggplot(df, aes(x = Risk, y = Reward))+ geom_point()+
xlim(0, 0.03)+
ylim(-0.0003, 0.0004)+
theme_classic()
希望这可以帮助!
推荐阅读
- visual-studio-code - vscode:如何更改“替换”和“下一个匹配”的热键
- ffmpeg - RTSP 馈送屏幕截止
- git - 无法解析路径中的非法字符
- python - Python:将输出重定向到 tkinter 后无法加入线程
- javascript - 如何在光滑的滑块按钮上添加边距
- html - 如何使按钮链接到同一页面中的另一个功能?
- spring - Hibernate 结合 AND 和 OR 查询
- wordpress - 具有不同 IP 地址的主机 Wordpress(使用 docker)
- node.js - 无法接收快速代码的响应在控制台中显示未定义
- v8 - V8字节码中“ToBooleanLogicalNot”是什么意思?