R 将不同数据框中的geom_文本添加到镶嵌面
我正在使用R 将不同数据框中的geom_文本添加到镶嵌面,r,ggplot2,facet-wrap,R,Ggplot2,Facet Wrap,我正在使用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)
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)
库(ggplot2)
df.mon我可能没有抓住要点,但是这个怎么样
# 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)))
#数据帧
df.mon我可能没有抓住要点,但是这个怎么样
# 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)))
#数据帧
你能合并这两个数据帧,使所有信息都在一个数据帧中吗?然后,添加一个选项的值会更容易,但我甚至不需要这样做。请检查接受的答案。你能合并两个数据帧以便所有信息都在一个数据帧中吗?然后,添加一个选项的值会更容易,但我甚至不需要这样做。请检查已接受的答案。