2

I'd like to achieve the following effect in R: Three shaded areas bounded by 6 lines

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.

dassouki
  • 6,286
  • 7
  • 51
  • 81

1 Answers1

2

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")

alt text

daroczig
  • 28,004
  • 7
  • 90
  • 124
  • And if you do not like the grey background, add `+ theme_bw()` at the end of last command. – daroczig Jan 14 '11 at 14:54
  • Thanks, I'm trying to figure this out and read about so I can use it on my data sets, this however, seems exactly what I'm looking fo – dassouki Jan 14 '11 at 14:55