开发者

R: Shaded area between multiple sets of data

I'd like to achieve the following effect in R:

R: Shaded area between multiple sets of data

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

R: Shaded area between multiple sets of data

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜