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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:34:09+00:00 2026-06-04T15:34:09+00:00

Problem here is a bit obvious I think. I’d like the legend placed (locked)

  • 0

Problem here is a bit obvious I think. I’d like the legend placed (locked) in the top left hand corner of the ‘plotting region’. Using c(0.1,0.13) etc is not an option for a number of reasons.

Is there a way to change the reference point for the co-ordinates so they are relative to the plotting region?

mtcars$cyl <- factor(mtcars$cyl, labels=c("four","six","eight"))
ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) + 
opts(legend.position = c(0, 1), title="Legend placement makes me sad")

enter image description here

Cheers

  • 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-04T15:34:11+00:00Added an answer on June 4, 2026 at 3:34 pm

    Update: opts has been deprecated. Please use theme instead, as described in this answer.

    The placement of the guide is based on the plot region (i.e., the area filled by grey) by default, but justification is centered.
    So you need to set left-top justification:

    ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) + 
      opts(legend.position = c(0, 1), 
           legend.justification = c(0, 1), 
           legend.background = theme_rect(colour = NA, fill = "white"),
           title="Legend placement makes me happy")
    

    enter image description here

    If you want to place the guide against the whole device region, you can tweak the gtable output:

    p <- ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) + 
      opts(legend.position = c(0, 1), 
           legend.justification = c(0, 1), 
           legend.background = theme_rect(colour = "black"),
           title="Legend placement makes me happy")
    
    gt <- ggplot_gtable(ggplot_build(p))
    nr <- max(gt$layout$b)
    nc <- max(gt$layout$r)
    gb <- which(gt$layout$name == "guide-box")
    gt$layout[gb, 1:4] <- c(1, 1, nr, nc)
    grid.newpage()
    grid.draw(gt)
    

    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 have a bit of an architecture problem here. Say I have two tables,
I have a bit of a problem here. I have a third party ActiveX
I have run into a bit of a problem here: I had a problem-specific
I have a feeling my problem is a bit strange, but here goes... I
Bit of an abstract problem here. I'm experimenting with the Domain Model pattern, and
i have a bit of logical problem here. I have a catalog of products
I'm facing a bit of an odd problem here. I just launched: http://claudiu.phpfogapp.com/ To
I have a bit of a weird problem here! I am trying to write
Like many other users out here I have a problem with el and events.
Having a bit of CSS problem here. First off, my HTML code: <p> <span

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.