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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:21:29+00:00 2026-06-15T10:21:29+00:00

I’m using xtsExtra to plot two xts objects. Consider the following call to plot.xts:

  • 0

I’m using xtsExtra to plot two xts objects.

Consider the following call to plot.xts:

plot.xts(merge(a,b),screens=c(1,2))

which is used to plot the xts objects a and b in two separate panels.

How do I control the spacing of the y-axes? Specifically, I’m running into the problem where the y-axis labels come too close or even overlap.

Ideally, I would like to specify a minimum padding which is to be maintained between the two y-axis labels. Any help is appreciated!

EDIT: A reproducible example:

#install if needed
#install.packages("xtsExtra", repos="http://R-Forge.R-project.org")
library(xtsExtra)

ab=structure(c(-1, 0.579760106421202, -0.693649703427259, 0.0960078627769613, 
0.829770469089809, -0.804276208608663, 0.72574639798749, 0.977165659135716, 
-0.880178529686181, -0.662078620277974, -1, 2.35268982675599, 
-0.673979231663719, 0.0673890875594205, 1.46584597734824, 0.38403707067242, 
-1.53638088345349, 0.868743976582955, -1.8394614923913, 0.246736581314485
), .Dim = c(10L, 2L), .Dimnames = list(NULL, c("a", "b")), index = structure(c(1354683600, 
1354770000, 1354856400, 1354942800, 1355029200, 1355115600, 1355202000, 
1355288400, 1355374800, 1355461200), tzone = "", tclass = "Date"), class = c("xts", 
"zoo"), .indexCLASS = "Date", .indexTZ = "", tclass = "Date", tzone = "")

plot.xts(ab,screens=c(1,2))

which produces:

y-axis labels too close

  • 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-15T10:21:30+00:00Added an answer on June 15, 2026 at 10:21 am

    Sorry this took so long. I was trying to figure out why my graph starts at Dec 04, 2012 and ends at Dec 13, 2012, when yours starts at Dec 05, 2012 and ends at Dec 14 2012. Can you check to make sure that the ab you posted above is the same ab you used to plot your graph?

    Also, I used library xts instead of xtsExtra. Is there a reason to use xtsExtra ?

    Here’s the code:

    library(xts)
    
    ab=structure(c(-1, 0.579760106421202, -0.693649703427259, 0.0960078627769613, 
               0.829770469089809, -0.804276208608663, 0.72574639798749, 0.977165659135716, 
               -0.880178529686181, -0.662078620277974, -1, 2.35268982675599, 
               -0.673979231663719, 0.0673890875594205, 1.46584597734824, 0.38403707067242, 
               -1.53638088345349, 0.868743976582955, -1.8394614923913, 0.246736581314485), .Dim = c(10L, 2L), .Dimnames = list(NULL, c("a", "b")), index = structure(c(1354683600, 
              1354770000, 1354856400, 1354942800, 1355029200, 1355115600, 1355202000, 
              1355288400, 1355374800, 1355461200), tzone = "", tclass = "Date"), class = c("xts", 
              "zoo"), .indexCLASS = "Date", .indexTZ = "", tclass = "Date", tzone = "")
    
    #Set up the plot area so that multiple graphs can be crammed together
    #In the "par()" statement below, the "mar=c(0.3, 0, 0, 0)" part is used to change
    #the spacing between the graphs.   "mar=c(0, 0, 0, 0)" is zero spacing.
    par(pty="m", plt=c(0.1, 0.9, 0.1, 0.9), omd=c(0.1, 0.9, 0.2, 0.9), mar=c(0.3, 0, 0, 0))
    
    #Set the area up for 2 plots
    par(mfrow = c(2, 1))
    
    #Build the x values so that plot() can be used, allowing more control over the format
    xval <- index(ab)
    
    #Plot the top graph with nothing in it =========================
    plot(x=xval, y=ab$a, type="n", xaxt="n", yaxt="n", main="", xlab="", ylab="")
    mtext(text="ab", side=3, font=2, line=0.5, cex=1.5)
    
    #Store the x-axis data of the top plot so it can be used on the other graphs
    pardat <- par()
    
    #Layout the x axis tick marks
    xaxisdat <- index(ab)
    
    #If you want the default plot tick mark locations, un-comment the following calculation
    #xaxisdat <- seq(pardat$xaxp[1], pardat$xaxp[2], (pardat$xaxp[2]-pardat$xaxp[1])/pardat$xaxp[3])
    
    #Get the y-axis data and add the lines and label
    yaxisdat <- seq(pardat$yaxp[1], pardat$yaxp[2], (pardat$yaxp[2]-pardat$yaxp[1])/pardat$yaxp[3])
    axis(side=2, at=yaxisdat, las=2, padj=0.5, cex.axis=0.8, hadj=0.5, tcl=-0.3)
    abline(v=xaxisdat, col="lightgray")
    abline(h=yaxisdat, col="lightgray")
    mtext(text="ab$a", side=2, line=2.3)
    lines(x=xval, y=ab$a, col="red")
    box() #Draw an outline to make sure that any overlapping abline(v)'s or abline(h)'s are covered
    
    #Plot the 2nd graph with nothing in it ================================
    plot(x=xval, y=ab$b,  type="n", xaxt="n", yaxt="n", main="", xlab="", ylab="")
    
    #Get the y-axis data and add the lines and label
    pardat <- par()
    yaxisdat <- seq(pardat$yaxp[1], pardat$yaxp[2], (pardat$yaxp[2]-pardat$yaxp[1])/pardat$yaxp[3])
    axis(side=2, at=yaxisdat, las=2, padj=0.5, cex.axis=0.8, hadj=0.5, tcl=-0.3)
    abline(v=xaxisdat, col="lightgray")
    abline(h=yaxisdat, col="lightgray")
    mtext(text="ab$b", side=2, line=2.3)
    lines(x=xval, y=ab$b, col="blue")
    box() #Draw an outline to make sure that any overlapping abline(v)'s or abline(h)'s are covered
    
    #Plot the X axis =================================================
    axis(side=1, label=format(as.Date(xaxisdat), "%b %d\n%Y\n") , at=xaxisdat, padj=0.4, cex.axis=0.8, hadj=0.5, tcl=-0.3)
    mtext(text="Date", side=1, line=2.5)
    

    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 using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I would like to run a str_replace or preg_replace which looks for certain words
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

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.