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

  • Home
  • SEARCH
  • 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 8869083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:23:57+00:00 2026-06-14T17:23:57+00:00

I am moving my plots into ggplot. Almost there except for this one (code

  • 0

I am moving my plots into ggplot. Almost there except for this one (code got from this previous question):

ggplot plot should look like this

#Set the bet sequence and the % lines
betseq <- 0:700 #0 to 700 bets
perlin <- 0.05 #Show the +/- 5% lines on the graph

#Define a function that plots the upper and lower % limit lines
dralim <- function(stax, endx, perlin) {
  lines(stax:endx, qnorm(1-perlin)*sqrt((stax:endx)-stax))
  lines(stax:endx, qnorm(perlin)*sqrt((stax:endx)-stax))
}

#Build the plot area and draw the vertical dashed lines
plot(betseq, rep(0, length(betseq)), type="l", ylim=c(-50, 50), main="", xlab="Trial Number", ylab="Cumulative Hits")
abline(h=0)
abline(v=35, lty="dashed") #Seg 1
abline(v=185, lty="dashed") #Seg 2
abline(v=385, lty="dashed") #Seg 3
abline(v=485, lty="dashed") #Seg 4
abline(v=585, lty="dashed") #Seg 5

#Draw the % limit lines that correspond to the vertical dashed lines by calling the
#new function dralim.
dralim(0, 35, perlin) #Seg 1
dralim(36, 185, perlin) #Seg 2
dralim(186, 385, perlin) #Seg 3
dralim(386, 485, perlin) #Seg 4
dralim(486, 585, perlin) #Seg 5
dralim(586, 701, perlin) #Seg 6

I can show how far I’ve got (not far):

ggplot(a, aes(x=num,y=s, colour=ss)) +geom_line() +stat_smooth(method="lm", formula="y~poly(x,2)") 

my attempt

To be clear. I am plotting my data over the reference lines (top image). The bottom image shows my data and my poor attempt at getting the reference lines (which obviously hasn’t worked).

  • 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-14T17:23:58+00:00Added an answer on June 14, 2026 at 5:23 pm

    What you were doing was fitting a parabola to your data, not drawing a previously defined parabola. It’s not too hard to adapt what you had to ggplot.

    Same start as you had (though betseq is not actually used anywhere)

    #Set the bet sequence and the % lines
    betseq <- 0:700 #0 to 700 bets
    perlin <- 0.05 #Show the +/- 5% lines on the graph
    

    Not instead of a function which draws lines, make a function which returns geom_lines (in a list) that are what you want. There is an implied aes(x=x, y=y) which will be given in the ggplot declaration later, but this defines the data points that make the parabolas.

    #Define a function that plots the upper and lower % limit lines
    dralim <- function(stax, endx, perlin) {
      c(geom_line(data = data.frame(x=stax:endx, 
                                    y=qnorm(1-perlin)*sqrt((stax:endx)-stax))),
        geom_line(data = data.frame(x=stax:endx, 
                                    y=qnorm(perlin)*sqrt((stax:endx)-stax))))
    }
    

    To save repetition, define the position of the vertical lines (edges), which also can be used to define the left and right endpoints of the parabolas (ranges).

    edges <- data.frame(x=c(0, 35, 185, 285, 485, 585, 700))
    ranges <- data.frame(left = edges$x[-nrow(edges)],
                         right = edges$x[-1] + 1)
    

    Now build the ggplot. There a single geom_vline to draw all the vertical lines (since we defined the positions in a single dataset). The unusual step is looping over the row (indices) of ranges and calling dralim with the corresponding left and right values (and perlin). This returns a list of lists of geom_lines, but that can just be added to a plot in the normal way and all the lines get added. The final two scale calls are just to set the labels and, in the case of the y axis, range.

    ggplot(mapping=aes(x=x,  y=y)) +
      geom_vline(data=edges, aes(xintercept = x), linetype="dashed") +
      lapply(seq_len(nrow(ranges)), 
             function(r) {dralim(ranges$left[r], ranges$right[r], perlin)}) +
      scale_y_continuous("Cumulative Hits", lim=c(-50,50)) +
      scale_x_continuous("Trial Number")
    

    enter image description here

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

Sidebar

Related Questions

Moving ahead from previous question .I have two rectangle and they look like this:
For moving an individual from one branch to another I realize that there are
Moving rails app to production and running into the routing issues. I've read this
Im moving from django to pylons, is there an admin app?
While moving a java file from one plug-in to another plug-in, a dialog box
Moving this question to a different thread, as requested. I'm trying to customize DocBook
when moving one file from one location to another i use rename('path/filename', 'newpath/filename'); how
Moving from jQuery 1.4.4 to jquery 1.6.4 started breaking my code related to radiobuttonlist.
Will moving views from one schema to another have any adverse effect on performance?
Moving into beta for a product I am pushing out I need to set

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.