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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:03:55+00:00 2026-06-07T16:03:55+00:00

I’m trying to plot multiple lines as a part of a single class in

  • 0

I’m trying to plot multiple lines as a part of a single “class” in ggplot2. I can plot something like the following:

image with 5 classes

But my issue is that I want to show n1, n2, and n3 as a single class (grey thin lines for each with a single name in the legend).

My problem is that if I create a new factor in the data frame in order to group them, I end up drawing the addition connection from the end of n1 (upper right) to the beginning of n2 (lower left) which adds a diagonal across my graph:

graph with one class

That’s closer to what I want, but has the additional diagonal line. If it matters, I’m computing these using ROCR then extracting the x and y points from the resultant performance object in order to produce these lines.

  • 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-07T16:03:57+00:00Added an answer on June 7, 2026 at 4:03 pm

    Here’s one way, but I don’t think you’ll like it very much:

    d1 <- data.frame(x = 1:10,
                     y = rep(1:2,each = 5),
                     grp = factor(rep(letters[1:2],each = 5),levels = letters[1:3]))
    d1 <- rbind(d1,data.frame(x = 1:2,y = c(NA,NA),grp = c('c','c')))
    
    d2 <- data.frame(x = 1:15,
                     y = rep(3:5,each = 5),
                     grp = rep(1:3,each = 5))   
    
    ggplot() + 
        geom_line(data = d1,aes(x = x,y = y,group = grp,colour = grp)) + 
        geom_line(data = d2,aes(x = x,y = y,group = grp),colour = "blue")
    

    enter image description here

    Note that your solution won’t work well with other kinds of data. It just happens that each of the three lines you want to merge into the same category in the legend begin and end in basically the same spot. If that weren’t the case, you’d end up with unwanted connector lines.

    The above method will work more generally, but as you can see isn’t less awkward. If anything it’s more inconvenient.

    This kind of issue has come up many times, and it could be that I’m forgetting a simpler solution. But in general, try to keep in mind that in exchange for ggplot2 saving you from having to construct every legend manually, you (frequently, but not always) are sacrificing some flexibility, compared to base graphics.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.