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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:59:32+00:00 2026-05-26T21:59:32+00:00

In an R session, given: foo <- matrix(1:25, 5, 5) image(foo) What is the

  • 0

In an R session, given:

foo <- matrix(1:25, 5, 5)
image(foo)

What is the best way for me to add a legend or key for the color gradient used on this image() plot of foo?

This is for a large dataset of global precipitation values so hacking something together with legend() doesn’t seem to be a viable option. filled.contour() has a number of side effects that I’m not happy with. I’m using image() because it is the simplest plotting method to layer or add onto.

For the moment, my biggest issue with filled.contour() is that I’m trying to add contours from a different dataset via contour() to the plot. With filled.contour(), the contours would need to be adjusted to account for the default gradient key on the side of the plot, though I suppose this would also be the case if I added a key to the image() plot.

Thank you kindly for your time.

For future reference:

When using filled.contour(), you can call contour() and/or map() in addition to any other function you like by assigning it to filled.contour()‘s plot.axes argument. It might be helpful to remember that you can stack multiple lines of code with braces.

  • 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-26T21:59:33+00:00Added an answer on May 26, 2026 at 9:59 pm

    Here’s some code adapted from the zernike package. You can use it all, or just pull out the piece which creates a gradient key.
    # written 13 April 2011 by CGWitthoft. Watch for updates from the
    # owner of the zernike package.

     pupilplot <- function (wf, cp = NULL, col = topo.colors(256), addContours = FALSE, 
    cscale = TRUE, ...) 
     {
         if (cscale) {
             mar.orig <- (par.orig <- par(c("mar", "las", "mfrow")))$mar
            on.exit(par(par.orig))
            w <- (3 + mar.orig[2]) * par("csi") * 2.54
            layout(matrix(c(2, 1), ncol = 2), widths = c(1, lcm(w)))
            par(las = 1)
            mar <- mar.orig
            mar[4] <- mar[2]
            mar[2] <- 1
            par(mar = mar) 
        thelist <- list(...)  
        findz <- which(names(thelist) == 'zlim')  
        if (length(findz) > 0 ) {   
            zlim <- thelist$zlim  
            }else{  
                    zlim <- range(wf, finite = TRUE) #the original line  
            } 
     # end of my hack  
            levels <- seq(zlim[1], zlim[2], length = length(col))
            plot.new()
            plot.window(xlim = c(0, 1), ylim = range(levels), xaxs = "i", yaxs = "i")
            rect(0, levels[-length(levels)], 1, levels[-1], col = col,  density = NA)
            axis(4)
             box()
            mar <- mar.orig
            mar[4] <- 0
            par(mar = mar)
        }
        if (is.null(cp)) {
            axis1 <- 1:nrow(wf)
            axis2 <- 1:ncol(wf)
        }
        else {
             axis1 <- ((1:nrow(wf)) - cp$xc)/cp$rx
            axis2 <- ((1:ncol(wf)) - cp$yc)/cp$ry
        }
        image(axis1, axis2, wf, col = col, asp = 1, xlab = "X", ylab = "Y",  ...)
         if (addContours) 
            contour(axis1, axis2, wf, add = TRUE)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a built-in way to know if a given session variable is a
Is there any way to specify that a given Controller or Action uses Session
Given this Global.asax.cs: using System; using System.Web; namespace Foo.Web { public class Global :
Given an example of calling two web services methods from a session bean, what
Someone can point me reliable method to run given application in different session of
I want to get a session loaded by the Session class given a particular
.NET's HttpSessionState using an InProc store seems to treat session variable key values as
A session token is given to the user when he starts running a facebook
I'm trying to determine how much time is left in a given ASP.NET session
An application I'm working on does all its queries by identifier using session.load(). Given

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.