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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:38:46+00:00 2026-05-21T16:38:46+00:00

I’m using the following code to draw plots of two different data on same

  • 0

I’m using the following code to draw plots of two different data on same graph. And it is working well. But the problem is I’m manually scaling the data. Is it possible to autoscale them?

Here is my script

gales <- read.table("input", header=TRUE)
attach(gales)
par(mar=c(5,4,4,4)+0.1)
plot(year,number,type="l",lwd=2,las=1, col="red")
title(main = list("Title", cex=1.5,
                  col="red", font=3))
par(new=T)
plot(year,feb,type="l",lwd=2, las=1,axes=F,ylab="",col="blue")
axis(4,las=1)
mtext(side=4,line=2.5,"feb")

Here is my data

year    number  feb
1950    600 20
1951    1200    5
1952    900 5
1953    800 5
1954    800 5
1955    1100    20
1956    600 6
1957    900 10
1958    1200    20
1959    1200    20
1960    800 6
1961    900 6
1962    800 10
1963    1200    20
1964    900 15
1965    600 10
1966    600 10
1967    600 10
1968    600 10
1969    600 10
1970    1200    20

gales <- structure(list(
    year = 1950:1970,
    number = c(600L, 1200L, 900L, 800L, 800L, 1100L, 600L, 900L, 1200L, 1200L, 800L, 900L, 800L, 1200L, 900L, 600L, 600L, 600L, 600L, 600L, 1200L),
    feb = c(20L, 5L, 5L, 5L, 5L, 20L, 6L, 10L, 20L, 20L, 6L, 6L, 10L, 20L, 15L, 10L, 10L, 10L, 10L, 10L, 20L)),
    .Names = c("year", "number", "feb"), class = "data.frame", row.names = c(NA, -21L)
)
  • 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-21T16:38:47+00:00Added an answer on May 21, 2026 at 4:38 pm

    I agree with Richie Cotton that having two axes is considered bad form.

    However, there is an alternative way of displaying the information that is conceptually sound. This is to scale the values between 0 and 1.

    Here is an example using ggplot.

    library(reshape2)
    library(ggplot2)
    
    gales <- structure(list(
      year = 1950:1970,
      number = c(600L, 1200L, 900L, 800L, 800L, 1100L, 600L, 900L, 1200L, 1200L, 800L, 900L, 800L, 1200L, 900L, 600L, 600L, 600L, 600L, 600L, 1200L),
      feb = c(20L, 5L, 5L, 5L, 5L, 20L, 6L, 10L, 20L, 20L, 6L, 6L, 10L, 20L, 15L, 10L, 10L, 10L, 10L, 10L, 20L)),
      .Names = c("year", "number", "feb"), class = "data.frame", row.names = c(NA, -21L)
    )
    

    Define a function that will scale values between [0; 1] corresponding to [min; max]

    range01 <- function(x){(x-min(x))/(max(x)-min(x))}
    
    gales$number <- range01(gales$number)
    gales$feb <- range01(gales$feb)
    

    Melt data to long format suitable for plotting in ggplot

    mgales <- melt(gales, id.vars="year")
    

    Create the plot

    ggplot(mgales, aes(x=year, y=value, group=variable, colour=variable)) +
      geom_line(size=2)
    

    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'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put

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.