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

The Archive Base Latest Questions

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

I want to split the legend on a plot into 2, so that the

  • 0

I want to split the legend on a plot into 2, so that the first 3 elements are separated from the 4th element by a gap of about 1 line height. I initially just tried to add a line-break before the 1st element:

legend("topright",col=1,lty=1:3,lwd=1,legend=c("leg1","leg2","\nleg3"), bty="n")

but this seems to increase the gap inbetween all the elements (is this documented behaviour?)

I then used 2 separate legends, setting the borders to "n" and using lines() to reconstruct the borders (incidentally, is there a way to suppress only 1 border of a legend?); although this works, it does require a lot of trial and error with the values of inset.

The default values of inset in legend() are c(0,0), but these obviously get adjusted in the initial call to legend(), based on the length of the text in the elements of that legend. According to ?legend, the value of a legend() call includes the

“numeric vectors of length length(legend), giving the x and y coordinates of the legend’s text(s).”

Is there anyway this can be converted into suitable values for the inset of the 2nd call so that the elements of both legends line up?

  • 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-30T17:35:51+00:00Added an answer on May 30, 2026 at 5:35 pm

    just specify NAs in the arguments where you want the space to be. You’ll need to give all the legend arguments as vectors.

        set.seed(2)
        plot(0:10, rnorm(11), col = sample(c("green", "blue"), 11, replace = TRUE), 
            pch = sample(c(3, 19), 11, replace = TRUE), xlim = c(0, 12))
        legend("topright", pch = c(3, 19, NA, 3, 19), 
            col = c("green", "green", NA, "blue", "blue"), 
            legend = c("green cross", "green dot", NA, "blue cross", "blue dot"))
    

    enter image description here

    Alternatively, if you want to make 2 calls to legend() for finer control, specify trace=TRUE in the arguments and it returns you the x and y coordinates you need.

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

Sidebar

Related Questions

I want to split a 400k line long log file from a particular line
I want to split a string into two variables, the first word and the
I want to split an iterable into two lists with alternating elements. Here is
I want to split this line: string line = First Name ; string ;
I want to split a CSV line into its separate fields, however in some
I want to split an address on semicolons ( ; ) into rows separated
I want to split a long text into smaller chunks, that will act as
I want to split an arithmetic expression into tokens, to convert it into RPN.
I want to split a command line like string in single string parameters. How
I want to split up the jQuery .js file into two, but I have

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.