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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:20:35+00:00 2026-05-24T01:20:35+00:00

Define: df <- data.frame( line1 = rep(seq(1,5,by=1),2), line2 = rep(seq(2,6,by=1),2), index = rep(seq(1,5,by=1),2), factor=rep(c(a,b),each=5))

  • 0

Define:

df <- data.frame(
        line1 = rep(seq(1,5,by=1),2), 
        line2 = rep(seq(2,6,by=1),2),
        index = rep(seq(1,5,by=1),2),
        factor=rep(c("a","b"),each=5))

where line1 and line2 are two variables, say height and weight.

This is the simple style I would want for each panel (I would also like to change size of point markers, but not use how):

plot(df$line1[df$factor=="a"], type = "o", ylim=c(0,6))
lines(df$line2[df$factor=="a"], type = "o", lty=2, pch=0)

When I try this:

library(lattice)
xyplot(c(line1,line2)~index|factor,data=df,type="o")

the program treats all points as if they belong on one line.

In addition I am not sure how to feed in the arguments for plot style to get the desired results.

PS1. Surprisingly I have Googled around and found lots of scatter plots (with linear fits, densities, etc.) and histogram examples of trellis graphs, but not one of the simple thing I am trying to do.

PS2. I would like to tag this question trellis but do not have reputation points to create tag. Any volunteers?

  • 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-24T01:20:36+00:00Added an answer on May 24, 2026 at 1:20 am

    The answer is actually very simple. Instead of combining line1 and line2 to a vector, just use the extended formula interface of xyplot :

    xyplot(line1+line2~index|factor,data=df,type="o")
    

    gives :

    enter image description here

    Check also ?xyplot read through the heaps of text and play a bit with the examples there. You’ll find out how to customize this with titles, legends and the likes.

    As you labeled ggplot2 as well, this is one possibility of getting it done with that package :

    require(ggplot2)
    require(reshape)
    df2 <- melt(df,id=c("index","factor"))
    
    qplot(index,value,variable,facets = .~factor ,
              data=df2,geom="line",colour=variable)
    

    Gives :

    enter image description here

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

Sidebar

Related Questions

Define: > dats <- list( df1 = data.frame(a=sample(1:3), b = as.factor(rep(325.049072M,3))), + df2 =
Define: df1 <-data.frame( id=c(rep(1,3),rep(2,3)), v1=as.character(c(a,b,b,rep(c,3))) ) s.t. > df1 id v1 1 1 a
Define: df <- data.frame(name=c(México,Michoacán),dat=c(1,2)) s.t. > df name dat 1 México 1 2 Michoacán
I'm trying to define a Data Driven Subscription for a report in SSRS 2005.
What is the best approach to define additional data for typedef enums in C?
What type of data I should define on my java model for PostgreSQL money
I need to define new UI Elements as well as data binding in code
Is it possible to define an array of text fields (or any data type)
Is there a concise way to define properties in a ViewModel for data binding
I can easily define a datatype for a node of a directed graph. 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.