Days     Profit
4672 5195  79823.72824
4673 5196  79823.72824
4674 5197  79823.72824
4675 5198  79823.72824
4676 5199  79823.72824
4677 5200  79823.72824
4678 5201  79823.72824
4679 5203  77760.56168
4680 5204  77760.56168
4681 5205  77760.56168
4682 5206  77760.56168
4683 5207  77760.56168
4684 5212  85379.47144
4685 5213  85379.47144
4686 5214  85379.47144
4687 5215  85379.47144
4688 5216  85379.47144

上面是我创建的数据框的一个示例,我只发布了一小部分,因为它大约有7000行 . 我正在尝试使用ggplot创建包含数据的折线图 . 我看到其他人发布的图表看起来非常漂亮和专业,但是当我创建我的时候却没有 . 下面你将看到我如何使用ggplot和我的图表结果 .

df <- data.frame(Days = Day_value, Profit = PnL_value)
 p <- ggplot(data=df, aes(x=Days, y=Profit)) + geom_line() + geom_point()

ggplot results

下图是我整个数据集的打印,而不仅仅是我共享的选择数据 . 需要注意的一点是,我的Days列并不总是递增1 .

理想情况下,我的图表看起来像只有1行而不是3行.Ideal Graph

当我检查结构时,我得到:

'data.frame':   6993 obs. of  2 variables:
 $ Days  : Factor w/ 6993 levels "100","1000","1001",..: 4180 4286 4397 4489 4598 4699 4810 4910 5008 5111 ...
 $ Profit: num  0 0 0 0 0 0 0 0 0 0 ...
NULL

当我运行它时,我也收到此错误:

geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?