我有一个ggplot显示使用geom_path表达式的数据图,以查看两个变量如何随时间移动 . 使用geom_text函数绘制起始年份和结束年份作为参考点 . 能否请您演示如何在同一个ggplot图中绘制每个geom_path曲线背后数据的平均值?这个平均值需要在图上显示为两个点,以表示我所显示的两条曲线中每条曲线的X坐标和Y坐标的平均值 .

我需要两个单独的数据集才能实现这一目标吗?

这是我的语法:

orbit.plot <- ggplot(orbit.data, aes(x=OpM, y=INVT, colour=Subj,     label=Year)) +
geom_point(size=7, shape=20) + geom_path(size=1.5) +
ggtitle("Title Orbits") +
geom_text(data=subset(orbit.data,Year==2006 | Year==2014), aes(label=Year,     vjust=1, hjust=1)) +
theme(panel.background = element_rect(fill = 'white', colour = 'red'),     panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
geom_vline(xintercept=0, size=1) +
geom_hline(yintercept=7, size=1) +
scale_y_continuous(limits = c(7, 15), breaks=seq(7,15,1/2))

这是我尝试使用另一个geom_point表达式绘制平均值的地方,遗憾的是,我的图表中没有显示任何内容 .

# geom_point(data=orbit.data, aes(x= mean(INVT), y=mean(OpM)))

这是我的数据集:

Year    Subj    OpM INVT
    2006    HMC 0.088   14.5
    2006    TMC 0.09    10.3
    2007    HMC 0.095   13.8
    2007    TMC 0.078   10
    2008    HMC 0.085   13.3
    2008    TMC 0.08    9.5
    2009    HMC -0.023  12.3
    2009    TMC 0.019   8
    2010    HMC 0.009   13.5
    2010    TMC 0.043   8
    2011    HMC 0.025   14.3
    2011    TMC 0.065   10
    2012    HMC 0.0199  13.2
    2012    TMC 0.029   8.5
    2013    HMC 0.06    13.8
    2013    TMC 0.055   9.5
    2014    HMC 0.088   13.8
    2014    TMC 0.065   9.75

非常感谢您的帮助 .

编辑:这是数据集的输入为suggesed:

structure(list(Year = c(2006L, 2006L, 2007L, 2007L, 2008L, 2008L, 
2009L, 2009L, 2010L, 2010L, 2011L, 2011L, 2012L, 2012L, 2013L, 
2013L, 2014L, 2014L), Subj = structure(c(2L, 1L, 2L, 1L, 2L, 
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L), .Label = c("TMC", 
"HMC"), class = "factor"), OPM = c(0.088, 0.09, 0.095, 0.078, 
0.085, 0.08, -0.023, 0.019, 0.009, 0.043, 0.025, 0.065, 0.0199, 
0.029, 0.06, 0.055, 0.088, 0.065), Invt = c(14.5, 10.3, 13.8, 
10, 13.3, 9.5, 12.3, 8, 13.5, 8, 14.3, 10, 13.2, 8.5, 13.8, 9.5, 
13.8, 9.75)), .Names = c("Year", "Subj", "OpM", "INVT"
), class = "data.frame", row.names = c(NA, -18L))