我使用ggplot2
在某个位置绘制了多年月降水总量:
library(ggplot2)
df.mon <- data.frame(id=rep("Station 1", 192),
month=rep(seq(1:12), 16),
year=rep(1999:2014, each=12),
monprec=runif(n=192, min=0, max=400))
ggplot(df.mon, aes(x=month, y=monprec)) +
geom_bar(stat="identity") +
theme_bw(base_size=18) +
facet_wrap(~year, ncol=3)
在同一图中,我要与年度总降水量,这是在第二个数据帧添加注释:
df.year <- data.frame(id=rep("Station 1", 16),
year=1999:2014,
totprec=runif(n=16, min=200, max=1000))
我的第一种方法是使用geom_text()
,但df.year
数据帧不具有可以用作month
的y
参数一个aes()
列。
任何想法,以帮助我实现我的目标?
我可能已经错过了点,但这个怎么样?
# Data frames
df.mon <- data.frame(id=rep("Station 1", 192),
month=rep(seq(1:12), 16),
year=rep(1999:2014, each=12),
monprec=runif(n=192, min=0, max=400))
df.year <- data.frame(id=rep("Station 1", 16),
year=1999:2014,
totprec=runif(n=16, min=200, max=1000))
# Plotting
library(ggplot2)
ggplot(df.mon, aes(x=month, y=monprec)) +
geom_bar(stat="identity") +
theme_bw(base_size=18) +
facet_wrap(~year, ncol=3) +
ylim(c(0, 500)) +
geom_text(data = df.year, aes(x = 6.25, y = 450, label = round(totprec)))
在这里,我只指定x
和y
坐标在aes
为geom_text
年降水量注解。