R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

library (ggplot2)
## Warning: package 'ggplot2' was built under R version 3.5.2
fun1 <- function(x) -x + 4 
fun2 <- function(x) -x + 2
  
x <- seq(0, 10)
mydf <- data.frame(x,y1 = fun1(x),y2 = fun2(x))
mydf <- transform(mydf, z= pmax(y1, y2))


g <- ggplot(mydf, aes(x = x)) + geom_line(aes(y = y1), color= 'blue') + geom_line(aes(y = y2), color= 'green')


g<- g + geom_ribbon(aes(ymin = y1, ymax= z), fill= 'gray80')
g

fun3 <- function(x) -x + 2 
fun4 <- function(x)  x - 1


mydf2 <- data.frame(x, y3 = fun3(x), y4 = fun4(x))
mydf2 <- transform(mydf2 , z= pmax(y3, y4))


g2 <- ggplot(mydf2, aes(x = x)) + geom_line(aes(y = y3), color= 'blue') + geom_line(aes(y = y4), color= 'green')


g2 <- g2 + geom_ribbon(aes(ymin = y4, ymax= z), fill= 'gray80')
g2