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

r@i@1290 m@iii@g oii @im@com r@i@1290 m@iii@g oii @im@com
Fri Apr 5 18:26:03 CEST 2019


Hi David,

Okay, I just gave this a try and was able to generate a shaded area using my existing code. But just to make sure that I am using this correctly, I did this using the following
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")
polygon(c(get,rev(get)), c(Hope2,rev(Hope9)),col="green")   #this is what I just tried


The polygon line that I just added there - am I telling R to shade everything from Hope2 to Hope9?
In this case, I have different x and y values for each "lines". Do I need to specify the polygon function each time I use the "lines" function in order to capture "all" of the green curves?
Thanks, again,
-----Original Message-----
From: David L Carlson <dcarlson using tamu.edu>
To: rain1290 using aim.com <rain1290 using aim.com>; r-sig-geo using r-project.org <r-sig-geo using r-project.org>
Sent: Fri, Apr 5, 2019 11:53 am
Subject: RE: [R-sig-Geo] Creating a color shade between upper and lower bounds of a line plot in R

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
	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list