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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:27:47+00:00 2026-06-01T12:27:47+00:00

I have an ggplot2 point chart created like this qplot(Index, Popularity ,data = data.slopeone.agg)

  • 0

I have an ggplot2 point chart created like this

qplot(Index, Popularity ,data = data.slopeone.agg)

now I would like to add a vertical line at the half of all data points. In other words, where the integral is 0.5. I want add this line to see wich part of the data makes 50%.

How can I achieve this in R? I know about geom_vline but don’t know how to determine the positon of the vline.

The data is structured like this:
Each row has an ItemId the popularity of this item and an index for my chart to display the values sorted by popularity.

head(data.slopeone.agg)
    Item Popularity Index
184  258 0.07695880     1
29    50 0.07294129     2
121  181 0.07162558     3
203  286 0.07030986     4
225  313 0.06500478     5
65   100 0.06366796     6

my chart looks like this: http://img838.imageshack.us/img838/3194/popt.png

  • 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-01T12:27:48+00:00Added an answer on June 1, 2026 at 12:27 pm

    I now found out how to solve my problem. Maybe it’s not the most elegant way:

    define a function to get the 50% of popularity data vertical line position

    getPopularityVLineIndex = function(popData){
    
      halfPopularity = sum(popData$Popularity) / 2
    
      # initialize helper variables
      fiftyPercent = 0;
      counter = 1;
    
      # sum up the popularity values until the half of the sum is reached
      while (fiftyPercent < halfPopularity) {
          fiftyPercent = fiftyPercent + popData$Popularity[which(popData$Index == counter)]
          counter = counter + 1
      }
    
      # the current counter value is the position of the vertical line
      vLineIndex = counter
    
      return (vLineIndex)
    }
    
    qplot(Index, Popularity ,data = popData) + geom_vline(xintercept = getPopularityVLineIndex(popData), colour="red", linetype = "longdash"))
    

    If somebody knows a more elegant way, feel free to post it. But maybe my question is now more understandable 😉

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

Sidebar

Related Questions

I have a scatter plot in R (with ggplot2). The data has a numeric
I have the following data set that I am trying to plot with ggplot2,
I'm plotting a group of curves, using facet in ggplot2. I'd like to have
When running this code (go ahead, try it): library(ggplot2) (myDat <- data.frame(cbind(VarX=10:1, VarY=runif(10)), Descrip=sample(LETTERS[1:3],
Let's say I have a list of plots that I've created. library(ggplot2) plots <-
I have the following problem: I would like to visualize a discrete and a
I have written the following code: library(ggplot2) data <- structure(list(x = c(1L, 6L, 3L,
I have a plot with overlapping shaded confidence intervals that looks like this: and
I have a facetted plot like this: ggplot(mtcars, aes(x = hp, y = mpg))
I produced biplot with this R code: set.seed(12345) require(ggplot2) AData <- data.frame(Glabel=LETTERS[1:7], A=rnorm(7, mean

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.