Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plot quantiles with ggplot2

Tags:

r

ggplot2

I am new to ggplot and I have some questions. I hope someone can help me out in making the plot I want to make.

How can I plot quantiles that were previously calculated, with ggplot2?

X=runif(34,min=4, max=89)

quantiles.X=quantile(X,probs=c(.01,.03,.05,.1,.15,.20,.50,.70,.80,.90,.95))
> quantiles.X
      1%        3%        5%       10%       15%       20%       50%       70%       80%       90%       95%

5.292614  5.813105  9.509620 20.036279 25.542286 28.704292 49.796086 68.832996 76.725968 77.947276 80.549077

edited

I was aiming for the display of the quantiles was a form of histogram style or line. Maybe to plot a line for each quantile over the point data will be more communicative/useful.

like image 652
Gago-Silva Avatar asked Aug 18 '26 15:08

Gago-Silva


1 Answers

You could something along these lines:

X=runif(34,min=4, max=89)
p = c(.01,.03,.05,.1,.15,.20,.50,.70,.80,.90,.95)
dat = data.frame(q = quantile(X, probs = p),
                 prob = p)

And then plot using ggplot2:

ggplot(aes(x = prob, y = q), data = dat) + geom_line()
like image 156
Paul Hiemstra Avatar answered Aug 20 '26 04:08

Paul Hiemstra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!