r - ggplot2 stat_function - can we use the generated y values on other layers -


This question arose when I tried to attract a standard normal distribution with ggplot (easy to do with stat_function) Trying the area under the curve for different quintills -

Enter image details here

I was able to do this with geom_line and geom_ribbon to do a data frame with a range of values ​​for x and the corresponding dnorm value for each x (X = seq (-3,3, length = out), with the "bottom", and

  data = data.frame (figures, iFeil (x & lefthinum; conomorum (0.2) 1000) Data $ y = dnorm (Data $ x) Data $ Quintil & lt; ifelse (x & lt; qnorm (0.4), "secs", ifelse (x & lt; qnorm (0.6), "middle", ifelse (X & lt; qnorm (0.8), "fourth", "top")))) data $ quintals & lt; - ggplot (data, aes (x = x, y = y, fill = quintile) - factor (data $ quantal, level = c ("bottom", "second", "middle", "fourth", "top")) ) + Geom_ribbon (AES (ymax = y), ymin = 0, alpha = 0.5) + geom_line (color = "black") + theme_bw () + theme (legend.position = "bottom") + Scale_fill_manual (values ​​= C (+ "darkgreen", "red", "purple", "blue", "gray")) + geom_vline (xintercept = c (qnorm (c (0.2,0.4,0.6, .8))) Size = 1) + Scale_y_continuous ("", breaks = NULL) + scale_x_continuous ("", breaks = NULL) , "color" = "c" ("darkgreen", "red", "purple", "blue"), size = 1)  

I find it more attractive to use stat_function and I think that to plot the line Will have to set a set of y values ​​- I tried to add colorful band to reach them on other layers, but unable to do this - I have to see that someone can explain how to do this or Why can not we?

Instead of creating the data itself, in another word, and to use the geom_line to draw the curve, I want to do something like

 < Code> ggplot (NULL, AES (x = c (-3,3)) + stat_function (fun = Dnorm)   

and use it to generate data which stat_function generated - I received the value of the generated y value (I tried to use .. ..) Was not able

Is there a way to use those values? if so?

  ggplot (null, aes (x = c (-3,3)))) + Stat_function (fun = dnorm, geom = "ribbon", mapping = aes (ymin = 0, ymax = .. y .. ..))    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -