首页 > 解决方案 > 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 中创建

标签: rggplot2

解决方案


我已按如下方式复制了您的数据框表(我假设您已经拥有它)

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()

您将获得如下输出: 在此处输入图像描述

希望这可以帮助!


推荐阅读