Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9001719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:28:26+00:00 2026-06-16T00:28:26+00:00

I have data that more or less looks like this (don’t know how to

  • 0

I have data that more or less looks like this (don’t know how to paste plots):

library(reshape2)
library(ggplot2)

df <- cbind(runif(2000,0,1000), rep(0,n=2000))
for (i in 1:nrow(df)) {
  df[i,2] <- runif(1, df[i,1], (10000-2*df[i,1])) 
}
colnames(df) <- c("x","y")
df.1 <- melt(data.frame(df), id="x")

p <- ggplot(df.1, aes(x=x, y=value))
p <- p + geom_point()
p <- p + geom_smooth()
p

Instead of the smooth line shown, I need one straight line at the bottom 5% and one straight line at the top 95%.
An issue is that I have millions of points, so I suppose data.table is a good way forward:

library(data.table)
dt <- data.table(df)
dt[,xbin:=0]
for (i in 0:100) {
  x1 <- i*100
  x2 <- (i+1)*100
  dt[x>=x1 & x<x2, xbin:=x2]
}
setkey(dt,xbin)
result1.dt <- dt[,list(ymin=min(y), ymax=max(y)), by=key(dt)]
result1.df <- data.frame(result1.dt)

p <- p + geom_line(data=result1.df, aes(x=xbin, y=ymin))
p <- p + geom_line(data=result1.df, aes(x=xbin, y=ymax))
p

The lines are not yet straight, but from here it is trivial to fix that.

Instead of min and max, how can I with data.table get 5th and 95th percentiles? Am I reinventing the wheel, i.e. is there already a statistical method for this (and a function)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:28:27+00:00Added an answer on June 16, 2026 at 12:28 am

    You can use stat_quantile to add these lines to your plot.

    p + stat_quantile(quantiles = c(0.05,0.95))
    

    enter image description here

    This uses quantile regression, specifically the rq function from the quantreg package.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have data that looks like this: #info #info2 1:SRX004541 Submitter: UT-MGS, UT-MGS Study:
I have a data that looks like this . And I intend to create
I have a WCF service that is hosted locally. My web.config looks like this:
We have some code that looks like this: class Serializer { public: template<class Type>
I have data which looks like this (this is test data for illustration): test
I have some code that looks like this (I left out the parts that
I have a service that will return 0 or more sets of data. The
I have the below markup that cannot be changed: <div>Some data</div> <span>More data</span> <a>Link
I have data that I would like to compute some statistics with. The data
I have some data that I would like to visualize. Each byte of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.