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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:15:43+00:00 2026-05-16T17:15:43+00:00

I have generated the following plot using the R code that follows it: ggplot(lengths,

  • 0

I have generated the following plot using the R code that follows it:
alt text

ggplot(lengths, aes(length, fill = library)) + geom_density(alpha = 0.2) + coord_cartesian(xlim = c(0, 60000)) 

Now I would like to make the plot a bit prettier:

  1. Make the x-axis show length every
    5000 units (instead of every 20000)
  2. Add x-values on top of the three
    peaks (approx 3000,5000 and 35000).

How can I do that?

update
in response to James:
alt text

  • 1 1 Answer
  • 2 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-16T17:15:44+00:00Added an answer on May 16, 2026 at 5:15 pm

    How about:

    (first create a reproducible example)

    set.seed(1001)
    lengths <- data.frame(length=c(rgamma(1000,shape=10,scale=500),
                        10000+rgamma(1000,shape=5,scale=700),
                        rnorm(500,mean=30000,sd=2000)),
                      library=factor(rep(2:1,c(2000,500))))
    

    (cute stuff to find peak locations and heights)

    peakfun <- function(x) {
      d <- density(x$length)
      peaks <- which(diff(sign(diff(d$y)))==-2)
      data.frame(x=d$x[peaks],y=d$y[peaks])
    }
    
    peakdat <- ddply(lengths,.(library),peakfun)
    peakdat <- peakdat[-1,] ## drop spurious peak
    

    (draw the plot)

    library(ggplot2)
    ggplot(lengths, aes(length, fill = library)) +
      geom_density(alpha = 0.2) +
      scale_x_continuous(limits = c(0,60000),
                         breaks = seq(0,60000,by=5000))+
      geom_text(data=peakdat,aes(x=x,y=y,label=round(x)),vjust=1)
    

    you probably want to tweak the vertical height of the labels a little

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

Sidebar

Related Questions

I have some geographic x,y,z data which I plot as follows p<-ggplot(aes(x=x,y=y,fill=z),data=my_data) I then
I have generated a pdf file with password protection by using the following code:
I have the following graph that I generated using ggplot2 I had finalPlot as
I have an application that uses Hibernate. It generated the following SQL statement. I
i have the following code: /** * @generated */ public class foo ... /**
I have following generated code and tried to retrive the radio button value or
In a ggplot2 density plot (geom_density) I have the following y-axis labels 0.000 0.005
I have just begun Rails 3. I have generated the below code using the
I had a model customer, which I have generated using the following rails g
I have the following classes generated by the Reverse engineering tool (Entity Framework Power

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.