Quantcast
Channel: グラフ - 廿TT
Viewing all articles
Browse latest Browse all 123

[ggplot2]折れ線グラフを基準値の上下で塗りつぶす

$
0
0

f:id:abrahamcow:20150829194656p:plain

library(ggplot2)
ybar <- mean(lh)
lh2 <- c(ybar,lh,ybar)
df4plot <-data.frame(time=1:length(lh2), lh=lh2)
df4plot$lower <- ifelse(lh2<=ybar,lh2,ybar)
ggplot(df4plot,aes(x=time,y=lh))+
  geom_line()+
  geom_polygon(aes(x=time, ymin=lower,ymax=lh),alpha=0.3)+
  geom_hline(yintercept=ybar)

Viewing all articles
Browse latest Browse all 123

Trending Articles