我有这样的数据:选择特定的列数据的geom点
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
我想绘制geom_point仅使用列ID ==“A”。
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时给我
"Warning: Ignoring unknown parameters: thedata"
。
UPDATE
使用:
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指出,
结果:
Error: ggplot2 doesn't know how to deal with data of class ts
的说法是'data'不是'thed ata'。您需要将data.frame传递给该参数;在你目前的代码中,它看起来像你正在使用矢量。 – aosmith
@aosmith:是的,我错过了'数据'的事情。我更新了,但仍然有错误。 – George
你是否试图使用dplyr中的'filter'或stats中的'filter'?如果前者是'thedata%>%filter(ID ==“A”)' – aosmith