2
このquestionのようにデータセットを考えてみましょう。陰影は、をggplot2
に次のようにプロットすることができます。シェーディングの凡例を追加する方法R ggplot2のgeom_rectへの凡例の追加
data <- structure(list(Time = c(20L, 40L, 60L, 80L, 100L, 120L, 20L,
40L, 60L, 80L, 100L), Average = c(5.8, 6.1, 6.4, 6.7, 7, 7.7,
8.47, 9.317, 10.2487, 11.27357, 12.40093), Test = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L), .Label = c("Control",
"Exp"), class = "factor"), n = c(9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L), se = c(0.12, 0.145, 0.188, 0.99, 0.44, 0.32,
0.5, 0.88, 0.9, 0.33, 0.456)), .Names = c("Time", "Average",
"Test", "n", "se"), class = "data.frame", row.names = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11")
ggplot(data, aes(x=Time, y=Average, colour=Test)) +
geom_rect(aes(xmin=20,xmax=30,ymin=-Inf,ymax=Inf),fill="pink",colour=NA,alpha=0.05) +
geom_errorbar(aes(ymin=Average-se, ymax=Average+se), width=0.2) +
geom_line() +
geom_point()
?