重新访问:geom_path:每个组仅包含一个观察值。您是否需要调整小组审美? [英] Revisit: geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?

查看:105
本文介绍了重新访问:geom_path:每个组仅包含一个观察值。您是否需要调整小组审美?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此数据框,我尝试使用以下代码:

Using this data frame, I attempted to create a simple line graph using the following code:

crypto_data<-
  crypto_data %>% gather(Cryptocurrencies, USD_Exchange, -Date)

ggplot(data = crypto_data) +
  geom_line(aes(x = Date, y = USD_Exchange, colour = Cryptocurrencies))

这显然产生了众所周知的错误。

This produced the, apparently, well known error.


访问:geom_path:每组仅包含一个观察值。您需要调整小组的审美吗?

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

我知道这个问题在这里得到了最明显的解决:

I am aware that this question has been addressed most notably here:

ggplot2折线图给出 geom_path:每组仅包含一个观察值。您是否需要调整组的审美?

但是,我绘制的图形不仅仅是一个变量。(即使Litecoin USD上的数据汇率仅在以后才开始,它在引入之前为零。)我也很注意在ggplot中的es()中规定组(请参见代码)。该命令生成的图形具有正确的轴标签和键,但绘图区为空白。

However, I am graphing more than a single variable.(Even though the data on the Litecoin USD exchange rate only starts at a later date it takes the value of zero prior to its introduction) I have also been mindful of stipulating the groups within aes() in ggplot (see the code). The command produces a graph with the correct axis lables and key, but a blank plotregion.

有人看到任何明显的错误或有解决办法吗?先感谢您。

Does anyone see any obvious errors or perhaps have a solution? Thank you in advance.

推荐答案

感谢编辑建议,找到了解决方案!

Thanks for the edit suggestion, have found a solution!

crypto_data <-
crypto_data %>% gather(Cryptocurrencies, USD_Exchange, -Date)
ggplot(data=crypto_data) +
geom_line(aes(x=as.numeric(Date), y = USD_Exchange, colour = Cryptocurrencies)

使Date变量(这是一个因子变量)成为数字...

Just had to make the Date variable (that was a factor variable) numeric...

这篇关于重新访问:geom_path:每个组仅包含一个观察值。您是否需要调整小组审美?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆