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

  • Home
  • SEARCH
  • 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 8080997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:35:11+00:00 2026-06-05T16:35:11+00:00

Consider the following: set.seed(1) RandData <- rnorm(100,sd=20) Locations <- rep(c(‘England’,’Wales’),each=50) today <- Sys.Date() dseq

  • 0

Consider the following:

set.seed(1)
RandData <- rnorm(100,sd=20)
Locations <- rep(c('England','Wales'),each=50)
today <- Sys.Date()
dseq <- (seq(today, by = "1 days", length = 100))

Date <- as.POSIXct(dseq, format = "%Y-%m-%d")

Final <- cbind(Loc = Locations, Doy = as.numeric(format(Date,format = "%j")), Temp = RandData)

In this example how is it possible to produce two plots in the same figure window, where the first plot shows the temperature in England against Doy and the second shows temperature in Wales against Doy?

  • 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-05T16:35:12+00:00Added an answer on June 5, 2026 at 4:35 pm

    Note that your data is a character matrix. Better if the Final object is created via:

    Final <- data.frame(Loc = Locations,
                        Doy = as.numeric(format(Date,format = "%j")),
                        Temp = RandData)
    

    With that, the code below draws two plots on the one window, side by side. I use the formula interface to plot() to make use of it’s subset argument, which works like the subset() function.

    ylab <- "Temperature"
    xlab <- "Day of year"
    
    layout(matrix(1:2, ncol = 2))
    plot(Temp ~ Doy, data = Final, subset = Loc == "England", main = "England",
         ylab = ylab, xlab = xlab)
    plot(Temp ~ Doy, data = Final, subset = Loc == "Wales", main = "Wales",
         ylab = ylab, xlab = xlab)
    layout(1)
    

    Which produces this plot:

    england wales temperatures

    If you want them both on the same scale then we modify it a bit:

    ylab <- "Temperature"
    xlab <- "Day of year"
    xlim <- with(Final, range(Doy))
    ylim <- with(Final, range(Temp))
    layout(matrix(1:2, ncol = 2))
    plot(Temp ~ Doy, data = Final, subset = Loc == "England", main = "England",
         ylab = ylab, xlab = xlab, xlim = xlim, ylim = ylim)
    plot(Temp ~ Doy, data = Final, subset = Loc == "Wales", main = "Wales",
         ylab = ylab, xlab = xlab, xlim = xlim, ylim = ylim)
    layout(1)
    

    which produces this version of the plot

    england wales temp with same scaling

    For a line-plot you’d need to get the data in Doy order and then add type = "l" to the plot() calls.

    For completeness, @Justin has shown how to use one of the high level plotting packages to achieve something similar but with less user-effort via ggplot2. The lattice package is another major high-level plotting package in R. You can achieve the same plot using lattice via:

    require(lattice)
    xyplot(Temp ~ Doy | Loc, data = Final, type = c("l","p")
    

    The latter produces

    england wales temp v3 via lattice

    Use type = "p" for just points and type = "l" for just lines. As you can see, the higher-level packages make producing these plots a bit easier than with the base graphics package.

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

Sidebar

Related Questions

I've been having this strange problem with apply lately. Consider the following example: set.seed(42)
Consider following script: SET LANGUAGE 'German' GO SET DATEFIRST 1 GO DECLARE @FullDate DATETIME
Consider following: $(#myform).attr({ action: @Url.Action(MVC.Thing.Delete().AddRouteValue(id, myJsModel.Id )) }); I'm trying to set the action
Consider the following declaration as part of SomeClass private Set<String> blah = new HashSet<String>();
Consider the following class public class Class1 { public int A { get; set;
consider the following class: class Order { int OrderId {get; set;} int CustomerId {get;
Please consider the following code: public class Person ( public string FirstName {get; set;}
Consider the following program. It creates a set of pointer-to-ints, and uses a custom
consider the following class and struct public class Entity { public IdType Id {get;set;}
Consider the following set up: - SomeFilter extends Filter - Filter implements Runnable -

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.