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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:20:26+00:00 2026-06-18T07:20:26+00:00

I have data conditioned on two variables, one major condition, one minor condition. I

  • 0

I have data conditioned on two variables, one major condition, one minor condition. I want a xyplot (lattice) with points and lines (type='b'), in one panel so that the major condition determines the color and the minor condition is used for drawing the lines.

Here is an example that is representative of my problem (see the code below to produce the data frame). d is the major condition, and c is the minor condition.

> dat
     x          y c d
1    1  0.9645269 a A
2    2  1.4892217 a A
3    3  1.4848654 a A
....
10  10  2.4802803 a A
11   1  1.5606218 b A
12   2  1.5346806 b A
....
98   8  2.0381943 j B
99   9  2.0826099 j B
100 10  2.2799917 j B

The way to get the connecting lines to be conditioned on c is to use groups=c in the plot. Then the way to tell them apart is to use a formula conditioned on d:

xyplot(y~x|d, data=dat, type='b', groups=c)

enter image description here

However, I want the plots in the same panel. Removing the formula condition on d produces one panel, but when group=d is specified, there are “retrace” lines drawn:

xyplot(y~x, data=dat, type='b', groups=d, auto.key=list(space='inside'))

enter image description here

What I want looks very like the above plot, only without these “retrace” lines.

It’s possible to set the colors explicitly in this example, as I know that there are five lines of category ‘A’ followed by five of category ‘B’, but this won’t easily work for my real problem. In addition, auto.key is useless when setting the colors this way:

xyplot(y~x, data=dat, type='b', groups=c, col=rep(5:6, each=5))

enter image description here

The data:

set.seed(1)
dat <- do.call(
  rbind,
  lapply(1:10,
         function(x) {
           firsthalf <- x < 6
           data.frame(x=1:10, y=log(1:10 + rnorm(10, .25) + 2 * firsthalf),
                                c=letters[x],
                                d=LETTERS[2-firsthalf]
                                )
         }
  )
)
  • 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-18T07:20:28+00:00Added an answer on June 18, 2026 at 7:20 am

    The default graphical parameters are obtained from the superpose.symbol and superpose.line. One solution s to set them using par.settings argument.

    ## I compute the color by group 
    col <-by(dat,dat$c,
                    FUN=function(x){
                      v <- ifelse(x$d=='A','darkgreen','orange')
                      v[1]  ## I return one parameter , since I need one color
                      }
             )
    
     xyplot(y~x, data=dat, type='b', groups=c,
           auto.key = list(text =levels(dat$d),points=F),
           par.settings=
             list(superpose.line   = list(col = col),                 ## color of lines
                  superpose.symbol = list(col=col),                   ## colors of points
                  add.text = list(col=c('darkgreen','orange'))))      ## color of text in the legend
    

    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 lattice graph with two conditions: one condition (x1) has 4 levels
I have a data.frame in R. I want to try two different conditions on
I have two data.frames, one with only characters and the other one with characters
I have data frame with two column say a and b now I want
i have data-grid in my application and i want to customize my data-grid so
I have data from two different sources that I need to combine. Some data
I am using C++ and MySQL. I have data objects I want to persist
I have three data frames and trying to calculate the difference between two data
I have two data tables, dt1 & dt2. dt1 has data while dt2 is
i have data (unsigned char data[480][640][4]) and two threads thisThread1FunctinIsCalledForExampleAbout50CallsPerSecond() { fill( data );

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.