[R-sig-Geo] Creating a color shade between upper and lower bounds of a line plot in R

David L Carlson dc@r|@on @end|ng |rom t@mu@edu
Fri Apr 5 17:53:34 CEST 2019


You can use the polygon() function (?polygon). Here's a simple reproducible example:

x <- 1:25
y1 <- sqrt(x)
y2 <- x/6
plot(x, y1, typ="l", ylim=c(0, 5))
lines(x, y2)
polygon(c(x, rev(x)) , c(y1, rev(y2)), col="green")
lines(x, y2+.5)

If there are lines hidden by the shading, plot them after the polygon or add an alpha value to the fill color you are using, e.g. 

greena <- rgb(0, 255/255, 0, .5)
polygon(c(x, rev(x)) , c(y1, rev(y2)), col=greena)

----------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352

-----Original Message-----
From: R-sig-Geo <r-sig-geo-bounces using r-project.org> On Behalf Of rain1290--- via R-sig-Geo
Sent: Friday, April 5, 2019 10:22 AM
To: r-sig-geo using r-project.org
Subject: [R-sig-Geo] Creating a color shade between upper and lower bounds of a line plot in R

Hello there,
I have many line plots on a single graph and would like to somehow create a shaded area between them so that it looks neater and easier to interpret. Something like this:
http://jvoigts.scripts.mit.edu/blog/assets/plot_shaded_pretty.png

I heard that the function "geom_ribbon" was ideal to do this, but is it possible to incorporate this in the basic "plot" command? If so, how?
This is currently what I have done with the basic plotting, which works fine:
plot(get, Hope2, type = "l",col = "green", lwd = "3", xlab="Cumulative CO2 emissions (TtC)", ylab = "One-day maximum precipitation (mm/day)", main = "One-day maximum precipitation for Random Area for CanESM2 scenarios")lines(IPSL, Hope6, type = "l", lwd = "3", col = "green")
lines(MIROC, Hope7, type = "l", lwd = "3", col = "green")
lines(subsetprime, Hope8, type = "l", lwd = "3", col = "green")
lines(MPI, Hope9, type =" l", lwd = "3", col = "green")
So, in this plot, I have 5 green line plots in one. The idea would be shade these in green, from the lower to upper bounds. Is this possible?
Any assistance would be extremely valuable!

	[[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo using r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list