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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:50:11+00:00 2026-05-30T02:50:11+00:00

I am using the sm package in R to draw a density plot of

  • 0

I am using the sm package in R to draw a density plot of several variables with different sample sizes, like this:

var1 <- density(vars1[,1]) 
var2 <- density(vars2[,1]) 
var3 <- density(vars3[,1]) 

pdf(file="density.pdf",width=8.5,height=8)
plot(var1,col="BLUE")  
par(new=T)
plot(var2,axes=FALSE,col="RED")  
par(new=T)
plot(var3,axes=FALSE,col="GREEN")  
dev.off()

The problem I’m having, is that I want the y-axis to show the proportions so I can compare the different variables with each other in a more meaningful way. The maxima of all three density plots are now exactly the same, and I’m pretty sure that they wouldn’t be if the y-axis showed proportions. Any suggestions? Many thanks!

Edit:

I just learned that I should not plot on top of an existing plot, so now the plotting part of the code looks like this:

pdf(file="density.pdf",width=8.5,height=8)
plot(var1,col="BLUE")  
lines(var2,col="RED")  
lines(var3,col="GREEN")  
dev.off()

The maxima of those lines however are now very much in line with the sample size differences. Is there a way to put the proportions on the y-axis for all three variables, so the area under the curve is equal for all three variables? Many thanks!

  • 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-30T02:50:12+00:00Added an answer on May 30, 2026 at 2:50 am

    Don’t plot on top of an existing plot, because they axes may be different. Instead, use lines() to plot the second and third densities after plotting the first. If necessary, adjust the ylim parameter in plot() so that they all fit.

    An example for how sample size ought not matter:

        set.seed(1)
        D1 <- density(rnorm(1000))
        D2 <- density(rnorm(10000))
        D3 <- density(rnorm(100000))
        plot(D1$x,D1$y,type='l',col="red",ylim=c(0,.45))
        lines(D2$x,D2$y,lty=2,col="blue")
        lines(D3$x,D3$y,lty=3,col="green")
    

    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'm calling a SSIS package using LoadPackage(...). Is it possible to make this call
I am building a Setup Package using VS2008. This is a regular setup package
I'm using a graphing package that can draw lines of color (255,255,255). So basically
I am trying to draw a (undirected) graph using the Tikz package, such that
In R, using maps package, and gcIntermediate function, how do I draw lines between
I am doing a project using the RGraph HTML5 canvas package to draw graphs.
This is a beginner question for java graphics using the awt package. I found
Hi I am using package-maker of Mac OS to create installer package for Mac
When I am using subfig package in latex, it gives some errors: Package subfig
I have created an installation package using Wix which installs a Windows service on

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.