Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206553

how to use syntax in geom_polygon?

$
0
0

sorry for the question, I am still new in this. I found a nice code in the internet which shades areas between graphs with polygon (I cannot use geom_ribbon). I have to rewrite it into the ggplot format, but I dont know which parameters I have to plug in.

#sample code
x1 <- seq(-3,3,0.01)
y1 <- dnorm(x,0,1)
y2 <- 0.5*dnorm(x,0,1)
plot(x1,y1,type="l",bty="L")
polygon(c(x1,rev(x1)),c(y2,rev(y1)),col="skyblue")


#I need the code in this format
d=data.frame(x1=x1, y1=y1, y2=y2)
ggplot(data= d) +
  geom_line(aes(x=x1,y=y1))+
  geom_line(aes(x=x1,y=y2))+
  geom_polygon(?????)

Does anyone know a solution? Thank you very much in advance for your help.


Viewing all articles
Browse latest Browse all 206553

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>