选择特定列数据到几何点

乔治

我有这个数据:

Date                ID  Value
10-Apr-17 12:02:30  A   4.107919756
10-Apr-17 12:02:31  A   4.107539119
10-Apr-17 12:02:32  A   5.503949115
10-Apr-17 12:02:33  B   5.842728032
10-Apr-17 12:02:34  B   8.516053634
10-Apr-17 12:02:35  B   1.515112486
10-Apr-17 12:02:36  B   5.224667007

我想仅使用列 ID == 'A' 来绘制 geom_point。

library(ggplot2)
library(lubridate)
library(magrittr)

thedata <- read.csv("~/Downloads/Vel.csv", header = TRUE)

thedata$newDate <- dmy_hms(thedata$Date)
ggplot(thedata, aes(newDate, Value)) +
    geom_point(thedata=thedata$ID %>% filter(thedata$ID == "A"))

但它绘制了所有点(A 和 B ID)。

它给了我

“警告:忽略未知参数:数据”

使用 ggplot 时。

更新

使用 :

thedata <- read.csv("~/Downloads/Vel.csv", header = TRUE)
thedata <- as.data.frame(thedata)
thedata$newDate <- dmy_hms(thedata$Date)
ggplot(thedata, aes(newDate, Value)) +
    geom_point(data=thedata$ID %>% filter(thedata$ID == "A"))

因此,使用数据作为数据框,而geom_point(data=thedata$ID %>%不是geom_point(thedata=thedata$ID %>%像@aosmith 指出那样使用

结果是 :

错误:ggplot2 不知道如何处理 ts 类的数据

保罗·恩迪米翁

我认为你应该这样做:

ggplot(thedata %>% dplyr::filter(ID == "A"), aes(newDate, Value)) +
geom_point()

关键是你不能geom在 ggplot() 中指定一个新的数据框时指定一个新的数据框。我想你也可以做这样的事情:

ggplot() +
geom_point(data = thedata %>% dplyr::filter(ID == "A"), aes(newDate, Value))

编辑 :

我更新了第二个代码块,所以它现在应该可以工作了。

关于 filter() 函数,您不需要thedata在您的情况下使用管道这项工作也一样,更容易阅读:geom_point(data = filter(thedata, ID == "A"), aes(newDate, Value))

此外,这只是我的意见,但我想您可以通过 ID 绘制整个数据和颜色会更有趣,如下所示:

ggplot() +
geom_point(data = thedata, aes(newDate, Value, colour = ID))

要完成ggplot()使用数据框进行馈送的问题,请注意您可以data为所有几何体指定不同,如本例中的mtcars数据集:

ggplot() +
     geom_point(data = mtcars, aes(mpg, disp, colour = cyl)) +
     geom_point(data = filter(mtcars, cyl == 6), aes(qsec, drat))

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Geopandas 对点(几何)到线串

Geopandas 数据框用于选择特定 ID 并在指定距离内查找几何图形

如何“选择特定数据,仅复制某些列并将其插入到不同的表中?”

从数据框列中选择特定值

如何选择数据框中的特定列?

选择多次出现的特定列数据

大型数据集 - 选择列后选择特定的行

使用tidyverse从列表到数据框,选择特定的列表元素

Geopandas df至lat / lon列中的匀称点几何

geoDjango点几何字段

查找最近的点(几何点)

从特定列中搜索数据,其中要选择的数据按特定列中的重复项排序

如何将 SQL Server 几何数据插入 postgis 几何数据类型列

如何在Java中将地图几何对象存储到MS-SQL几何列?

从SQL数据库中选择特定的行和列

从数据框中的列中选择特定值

如何从multiIndex数据框中选择特定的列?

在熊猫数据数组中选择特定的行和列

排序后如何仅从数据集中选择特定列

从pandas数据框中选择特定的索引,列对

选择特定月份数据时的列不明确

使用列值从大型数据集中选择特定行

如何从未堆叠的Pandas数据框中选择特定的列?

pandas-选择与特定索引对应的数据框列

从数据框中的特定列中选择奇数行

如何选择数据框的特定列,并根据条件对其求和?

R循环从多个数据框中选择特定的列

networkx可以从csv数据中选择特定的列吗?

从数据库中选择列的特定部分(oracle)