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 625745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:20:35+00:00 2026-05-13T19:20:35+00:00

I’m taking my first course in multiple linear regression, so I’m still a beginner

  • 0

I’m taking my first course in multiple linear regression, so I’m still a beginner in R. We’ve recently learned a bit about taking slices of bivariate scatterplot data, both horizontally and vertically. What I’d like to know is how to go beyond a basic scatterplot, and take advantage of conditionally grouping data by slices to examine patterns.

As an example, I’m working with high-octane data from a bank where we’re regressing employee’s current salary csalary onto their beginning salary bsalary. Here’s what my dataframe looks like.

  
    > str(data)
    'data.frame':   474 obs. of  10 variables:
     $ id     : num  628 630 632 633 635 637 641 649 650 652 ...
     $ bsalary: num  8400 24000 10200 8700 17400 ...
     $ gender : Factor w/ 2 levels "Male","Female": 1 1 1 1 1 1 1 1 1 1 ...
     $ time   : num  81 73 83 93 83 80 79 67 96 77 ...
     $ age    : num  28.5 40.3 31.1 31.2 41.9 ...
     $ csalary: num  16080 41400 21960 19200 28350 ...
     $ educlvl: num  16 16 15 16 19 18 15 15 15 12 ...
     $ work   : num  0.25 12.5 4.08 1.83 13 ...
     $ jobcat : Factor w/ 7 levels "Clerical","Office Trainee",..: 4 5 5 4 5 4 1 1 1 3 ...
     $ ethnic : Factor w/ 2 levels "White","Non-White": 1 1 1 1 1 1 1 1 1 1 ...
  

To explore the relationship of bsalary and csalary I created a scatterplot using some of the functionality of lattice library. I arbitrarily drew vertical lines at $5000 intervals along bsalary.

  
    library (lattice)
    # Constructing vertical "slices" of our csalary ~ bsalary data
    # First we define a vector with our slice points, in this case 
    # $5,000 bsalary increments
    bslices = seq (from = 5000, to = 30000, by = 5000)
    length (bslices)
    xyplot (csalary ~ bsalary,
        main  = "Current Bank Employee Salary as Predicted by Beginning Salary",
        xlab  = "Beginning Salary ($USD)",
        ylab  = "Current Salary ($USD)",
        panel = function(...){
            panel.abline(v = bslices, col="red", lwd=2);
            panel.xyplot(...);
        }
    )
  

The above code gets me this.

Rplot002.pdf (1 page)
(source: skitch.com)

Which is fantastic. But I feel like there ought to be a simple way to generate, from my data, graphs that group slice data into boxplots:

01LinReg.pdf (page 3 of 25)
(source: skitch.com)

Or stacked-dot scatterplots, again grouped by slice, like this:

01LinReg.pdf (page 3 of 25)
(source: skitch.com)

Ultimately, my question is how to turn raw scatterplot data into conditionally-grouped data. I feel like there are some simple, underlying features of lattice (or even the simpler plot commands that don’t require it) that would allow me to start slicing my data to explore for patterns.

Thanks in advance for your help!

  • 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-05-13T19:20:35+00:00Added an answer on May 13, 2026 at 7:20 pm

    you can use the cut() function to slice your data into ordinal categories. Then ggplot2’s qplot function can then very easily create your desired plots.

    library(ggplot2)
    
    #fake data
    csalary <- rnorm(100,,100)
    bsalary <- csalary +rnorm(100,,10)
    
    #Regular Scatter Plot
    qplot(bsalary,csalary)
    
    #Stacked dot plot
    qplot(cut(bsalary,10),csalary)
    
    #box-plot
    qplot(cut(bsalary,10),csalary,geom="boxplot")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.