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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:54:42+00:00 2026-05-27T15:54:42+00:00

Context and Question: I want to add a legend to a lattice plot in

  • 0

Context and Question:

I want to add a legend to a lattice plot in R that shows the density of two groups.
I’ve changed the default colours to black and gray. However, the legend has not updated the colours.

  • How can I get the lattice plot to use my updated colours in the legend?
  • How can I control the position of the legend (I’d like to be able to place it inside the plot area)?

Working example:

set.seed(4444)
x1 <- rep("Group A", 50)
x2 <- rep("Group B", 50)
y1 <- rnorm(50, 0, 2)
y2 <- rnorm(50, 1, 2)
dtf <- data.frame(x=c(x1, x2), y =c(y1, y2))

print(densityplot(~y, groups=x, data=dtf,
    pch=".",
    cex=2,
    col=c("black", "gray"),
    auto.key=TRUE,
    xlab="Y"))

enter image description here

  • 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-27T15:54:42+00:00Added an answer on May 27, 2026 at 3:54 pm

    The legend color is a well-known annoyance in lattice. It looks like it is difficult to correct, because Deepayan recommends simpleTheme as a solution. For positioning, see Josh’s answer.

    print(densityplot(~y, groups=x, data=dtf,
                  pch=".",
                  cex=2,
                  par.settings=simpleTheme(col=c("gray","black")),
                  auto.key=TRUE,
                  xlab="Y"))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question is exactly that but in context I want to examine the selection
In the context of this question link text is possible from a Controller that
I have a LinearLayout view that already contains several elements. I want to add
The context: My question relates to improving web-page loading performance, and in particular the
Here the context for my question: A common technique is to declare the parameter
First of all, the context of this question is: Cannot install psycopg2 on OSX
(See question below for more context): Are there any situations in which <machineKey validationKey=AutoGenerate,IsolateApps
This question has been asked in a C++ context but I'm curious about Java.
My question is pretty much summed up in the subject.The context is a problem
Update: Please read this question in the context of design principles, elegance, expression of

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.