在 facet wrap 图中绘制或突出显示其他值

Plot or highlight additional values in facet wrap graph

我有一些时间序列数据,我使用了一些函数来查找特定的 x、y 坐标,并希望在我创建的小平面图中突出显示它们。甚至不确定是否可能。

# create sample data
t<-seq(1:100)
a<-rnorm(1:100)
b<-rnorm(1:100)
c<-rnorm(1:100)
g <-as.data.frame(cbind(t,a,b,c))
g <- melt(g,id="t")

# current facet graph
ggplot(g,aes(x=t,y=value,color=variable))+
  geom_point()+
  facet_wrap(~variable)

这看起来与我现在所获得的一致。但我还有下面的附加数据,它是 x,y 坐标的数据框。

# sample data with x,y coords
x1 <- c(10,11,15)
y1 <- c(5,6,9)
x2 <- c(50,41,35)
y2 <- c(25,27,19)
xy<-rbind(x1,y1,x2,y2)
colnames(xy)<-c("a","b","c")

我不确定如何做到这一点。我希望在各自的图中绘制坐标。

感谢楼上的帮助,因为你们怀疑我的数据格式不正确。我还是个新手,所以收集和格式化数据通常不是那么简单。

#the format of my 'primary' dataframe
t<-seq(1:100)
a<-rnorm(1:100)
b<-rnorm(1:100)
c<-rnorm(1:100)
g <-as.data.frame(cbind(t,a,b,c))
g <- melt(g,id="t")

#and then converting the original dataframe above to something that matches
xy<-data.frame(t = c(10,11,15,50,41,35),variable=c('a','b','c'),value = c(5,6,9,25,27,19))

一旦我将 df 转换为正确的格式,fiddle 就变得容易多了。

ggplot(g,aes(x=t,y=value,color=variable))+
  geom_point()+
  geom_point(data=xy,size=4) +
  facet_wrap(~variable)

下图显示了结果。也许这个问题的更好标题是 在单个面上绘制多个数据帧