R: Shaded area between multiple sets of data
I'd like to achieve the following effect in R:
I got 6 sets set of data in the following form:
- Series 1:
- a_1 <- c(1,2,3,4,5,6)
- a_2 <- c(2,3,4,5,6,7)
- Series 2:
- b_1 <- c(2,6,4,7,4,7,3,5,8,5,4)
- b_2 <- c(2开发者_如何学编程,3,4,4,5,6,2,4,6,7,3)
- Series 3:
- c_1 <- c(8,7,6,5,4,3)
- c_2 <- c(6,5,4,3,2,1)
I'd like to smooth the lines and color the areas in between them.
I have just deleted my answer given a minute before, as I realized you do not want to smooth a line around points, but just want to show areas between them, and the points are counted before visualization.
This way plotting could be very easy with geom_ribbon from ggplot2 package.
For example:
# load package
library(ggplot2)
# generate some data
huron <- data.frame(year = 1875:1972,level = as.vector(LakeHuron))
huron$level2 <- huron$level+runif(nrow(huron))*10-5
# plot
h <-ggplot(huron, aes(x=year))
h + geom_ribbon(aes(ymin=level-1, ymax=level+1)) + geom_ribbon(aes(ymin=level2-1, ymax=level2+1), color="red", fill="red")
精彩评论