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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:01:27+00:00 2026-05-23T10:01:27+00:00

I would like to make a plot with 4 axes in R so that

  • 0

I would like to make a plot with 4 axes in R so that it looks similar to this plot:

enter image description here

I’ve looked at the Quick-R website for advice and modified one of their examples (called A Silly Axis Example):

    # specify the data
x <- c(1:5); y <- x/2; 
w <- c(2:4)
z <- c(1:5)

# create extra margin room on the right for an axis
par(mar=c(5, 4, 4, 8) + 0.1)

# plot x vs. y
plot(x, y,type="b", pch=21, col="red",
   yaxt="n", lty=3, xlab="", ylab="")

# add x vs. 1/x
lines(x, z, type="b", pch=22, col="blue", lty=2)

# draw an axis on the left
axis(2, at=x,labels=x, col.axis="red", las=2)

# draw an axis on the right, with smaller text and ticks
axis(4, at=w,labels=round(w,digits=2),
  col.axis="blue", las=2, cex.axis=0.7, tck=-.01)

# draw an axis on the top
axis(3, at=z,labels=round(z,digits=2),
  col.axis="blue", las=2, cex.axis=0.7, tck=-.01)

# add a title for the right axis
mtext("L", side=3, line=3, cex.lab=1,las=2, col="blue")

# add a title for the right axis
mtext("OSR", side=4, line=3, cex.lab=1,las=2, col="red")

# add a main title and bottom and left axis labels
title("", xlab="GSI",   ylab="FSI")

This code produces the following plot:
enter image description here

I’m having difficulty figuring out how different axes can have different scales. For example, I want the top axis L, to go from 5 – 13, but if I set z <-c(5:13) it will not set the axis to these values. However, I can overwrite what the labels are:

axis(3, at=z,labels=round(c(9:13),digits=2), col.axis="blue", 
las=2, cex.axis=0.7, tck=-.01)

but then if I want to plot a point with these four parameters, the point will not show up in the correct place. How should I do this?

  • 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-23T10:01:28+00:00Added an answer on May 23, 2026 at 10:01 am

    One (perhaps cumbersome) option would be to write conversion functions that transform values between your two scales. Assuming you know the data ranges for both the top and bottom axes ahead of time, you could write a function like this:

    convertScaleToBottom <- function(x,botRange,topRange){
        temp <- (x - topRange[1]) / (topRange[2] - topRange[1])
        return(botRange[1] + (temp * (botRange[2] - botRange[1])))
    }
    

    that takes a set of values, x, in the top axis scale and converts them to the bottom axis scale. Then you can plot the converted values and retain the originals as the labels:

    z1 <- 5:13
    z1Adj <- convertScaleToBottom(z1,range(x),range(z1))
    
    # draw an axis on the top
    axis(3, at=z1Adj,labels=round(z1,digits=2),
         col.axis="blue", las=2, cex.axis=0.7, tck=-.01)
    

    This method is easily modified to reverse the order of the top axis:

    convertScaleToBottomRev <- function(x,botRange,topRange){
        temp <- (x - topRange[1]) / (topRange[2] - topRange[1])
        return(botRange[2] - (temp * (botRange[2] - botRange[1])))
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to make a log-probability plot for my data. I looked up
Would like to make anapplication in Java that will not automatically parse parameters used
I would like to make a nightly cron job that fetches my stackoverflow page
I would like to make a child class that has a method of the
I would like to make a simple web app that displays 20 or so
I would like to make a matplotlib plot having only the left and bottom
I would like to make California's map by the contour plot. However, I do
I would like to create a graph like this one using gnuplot (or matplotlib,
I would like to make a script that outputs only the real time value
I would like to plot discrete values in MATLAB like this: stairs() and stem()

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.