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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:00:48+00:00 2026-05-29T15:00:48+00:00

I have two related problems. Problem 1 : I’m currently using the code below

  • 0

I have two related problems.

Problem 1: I’m currently using the code below to generate a histogram overlayed with a density plot:

hist(x,prob=T,col="gray")
axis(side=1, at=seq(0,100, 20), labels=seq(0,100,20))
lines(density(x))

I’ve pasted the data (i.e. x above) here.

I have two issues with the code as it stands:

  • the last tick and label (100) of the x-axis does not appear on the histogram/plot. How can I put these on?
  • I’d like the y-axis to be of count or frequency rather than density, but I’d like to retain the density plot as an overlay on the histogram. How can I do this?

Problem 2: using a similar solution to problem 1, I now want to overlay three density plots (not histograms), again with frequency on the y-axis instead of density. The three data sets are at:

  1. http://pastebin.com/z5X7yTLS

  2. http://pastebin.com/Qg8mHg6D

  3. http://pastebin.com/aqfC42fL

  • 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-29T15:00:49+00:00Added an answer on May 29, 2026 at 3:00 pm

    Here’s your first 2 questions:

        myhist <- hist(x,prob=FALSE,col="gray",xlim=c(0,100))
        dens <- density(x)
        axis(side=1, at=seq(0,100, 20), labels=seq(0,100,20))
        lines(dens$x,dens$y*(1/sum(myhist$density))*length(x))
    

    The histogram has a bin width of 5, which is also equal to 1/sum(myhist$density), whereas the density(x)$x are in small jumps, around .2 in your case (512 even steps). sum(density(x)$y) is some strange number definitely not 1, but that is because it goes in small steps, when divided by the x interval it is approximately 1: sum(density(x)$y)/(1/diff(density(x)$x)[1]) . You don’t need to do this later because it’s already matched up with its own odd x values. Scale 1) for the bin width of hist() and 2) for the frequency of x length(x), as DWin says. The last axis tick became visible after setting the xlim argument.

    To do your problem 2, set up a plot with the correct dimensions (xlim and ylim), with type = "n", then draw 3 lines for the densities, scaled using something similar to the density line above. Think however about whether you want those semi continuous lines to reflect the heights of imaginary bars with bin width 5… You see how that might make the density lines exaggerate the counts at any particular point?

    enter image description here

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

Sidebar

Related Questions

I have two cmake-related problems: first, I can't make it to find the includes
I have two problems related to image presentation in FancyBox2: Images are automatically applied
I have two problems that I'm not sure are related: I have two DropDownList
I have a problem that I have found many similar problems related to multi
I have two related problems that occur in the following situation. I have a
Hi I have two related problems, i created a pop-up box that appears after
Below, I have written simple code that re-creates problems that have emerged as my
I have two somewhat related problems, shown by the following: user=> (if (symbol? 5)
I have two related classes which share a common interface and are both stored
I have two related tables in my database: Page and Tag. One Page can

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.