我有這樣的數據:選擇特定的列數據的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