Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中带有ggplot2的散点图:_R_Ggplot2_Rstudio_Scatter Plot - Fatal编程技术网

R中带有ggplot2的散点图:

R中带有ggplot2的散点图:,r,ggplot2,rstudio,scatter-plot,R,Ggplot2,Rstudio,Scatter Plot,我有以下数据集 > y DF GE 2006-12-21 -0.0004659447 -0.009960682 2006-12-22 -0.0009323238 -0.005295208 2006-12-26 -0.0032661785 0.003726377 2006-12-27 0.0042131332 0.002121453 2006-12-28 -0.0009323238 -0.008203228 2006-12-29

我有以下数据集

> y
                  DF           GE
2006-12-21 -0.0004659447 -0.009960682
2006-12-22 -0.0009323238 -0.005295208
2006-12-26 -0.0032661785  0.003726377
2006-12-27  0.0042131332  0.002121453
2006-12-28 -0.0009323238 -0.008203228
2006-12-29 -0.0135313109 -0.007203842
当我加固它时,它变成了这样

> fortify(y, melt=TRUE)
    Index     Series         Value
1  2006-12-21     DF -0.0004659447
2  2006-12-22     DF -0.0009323238
3  2006-12-26     DF -0.0032661785
4  2006-12-27     DF  0.0042131332
5  2006-12-28     DF -0.0009323238
6  2006-12-29     DF -0.0135313109
7  2006-12-21     GE -0.0099606815
8  2006-12-22     GE -0.0052952078
9  2006-12-26     GE  0.0037263774
10 2006-12-27     GE  0.0021214532
11 2006-12-28     GE -0.0082032284
12 2006-12-29     GE -0.0072038420
现在我想在ggplot2中运行一个散点图。目前,我使用的函数如下

x <- fortify(x, melt=TRUE)
ggplot(data=x) +
geom_point(size=10, aes(x=Series, y=Value, colour=Index))
但我真正想要的是一个散点图,其中DF和GE的值是X轴和Y轴上的坐标,日期用颜色显示


我根本不知道如何修改数据结构来实现这一点。

你的意思是这样的吗

library(tidyverse)
df %>%
    rownames_to_column("date") %>%
    mutate(date = as.Date(date)) %>%
    ggplot(aes(x = DF, y = GE)) +
    geom_point(aes(colour = date))
样本数据
你是说像这样的事吗

library(tidyverse)
df %>%
    rownames_to_column("date") %>%
    mutate(date = as.Date(date)) %>%
    ggplot(aes(x = DF, y = GE)) +
    geom_point(aes(colour = date))
样本数据 我不会使用强化。我会保留您的数据,并执行以下操作:

library(tidyverse)

y %>%
rownames_to_column() %>%   
ggplot(aes(x = DF, y = GE, color = index) + 
geom_point()
我不会使用强化。我会保留您的数据,并执行以下操作:

library(tidyverse)

y %>%
rownames_to_column() %>%   
ggplot(aes(x = DF, y = GE, color = index) + 
geom_point()

正是我需要的。谢谢,这正是我需要的。非常感谢。