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

The Archive Base Latest Questions

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

The Problem As I experiment with heatmaps, here’s a circular question, with a probably

  • 0

The Problem

As I experiment with heatmaps, here’s a circular question, with a probably frustratingly obvious answer…

I answered a question on plotting a heatmap with dissimilar data using the fields and ggplot2 packages. It basically allows very differently scaled x and y axes to be interpolated with the akima package ready for plotting.

Unfortunately, I can’t work out a way to relabel the axes so they refer back to the original values. I know it will involve the use of breaks and labels parameters in ggplot2 but I have been unable to produce anything but mistakes. Solutions for both the plotting packages would be much appreciated…

Updated with solution

For convenience, here is my code using ggplot2:

library("akima")
library("ggplot2")

x.orig <- rnorm(20, 4, 3)
y.orig <- rnorm(20, 5e-5, 1e-5)
x <- scale(x.orig)  
y <- scale(y.orig) 
z <- rnorm(20)

t. <- interp(x,y,z)
t.df <- data.frame(t.)

gt <- data.frame( expand.grid(x=t.$x, 
                              y=t.$y), 
                  z=c(t.$z), 
                  value=cut(c(t.$z), 
                            breaks=seq(min(z),max(z),0.25)))

p <- ggplot(gt) + geom_tile(aes(x,y,fill=value)) + 
    geom_contour(aes(x=x,y=y,z=z), colour="black") 

# --------------------------------------------------------------
# Solution below prompted by X. He's answer:

get.labels <- function(break.points, orig.data, scaled.data, digits) { 
    labels <- as.character(lapply(break.points,      
            function(i) round(i * min(orig.data) 
                              / min(scaled.data),
                              digits)
                                  )
                           )
    labels
}

x.break.points <- seq(min(x), max(x), 0.5)
x.labels <- get.labels(x.break.points, x.orig, x, digits=2)
p <- p + scale_x_continuous(breaks=x.break.points, 
                            labels=x.labels)

y.break.points <- seq(min(y), max(y), 0.5)
y.labels <- get.labels(y.break.points, y.orig, y, digits=8)
p <- p + scale_y_continuous(breaks=y.break.points, 
                            labels=y.labels)

p

The Result

Correctly labeled heat map

Still to be solved

There remains one issue: when the code is first run, it generates the labels in reverse, on the second and subsequent runs, the labels are correctly labeled. Maybe another question?…

  • 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-05T00:11:01+00:00Added an answer on June 5, 2026 at 12:11 am

    I did something like this:

    library("akima")
    library("ggplot2")
    
    x.orig <- rnorm(20, 4, 3)
    y.orig <- rnorm(20, 5e-5, 1e-5)
    x <- scale(x.orig)  
    y <- scale(y.orig) 
    z <- rnorm(20)
    
    t. <- interp(x,y,z)
    t.df <- data.frame(t.)
    
    gt <- data.frame( expand.grid(x=t.$x, 
                                  y=t.$y), 
                      z=c(t.$z), 
                      value=cut(c(t.$z), 
                                breaks=seq(min(z),max(z),0.25)))
    
    p <- ggplot(gt) + geom_tile(aes(x,y,fill=value)) + 
        geom_contour(aes(x=x,y=y,z=z), colour="black") 
    
    get.labels <- function(break.points, orig.data, scaled.data, digits) { 
        labels <- as.character(lapply(break.points,      
                function(i) round(i * min(orig.data) 
                                  / min(scaled.data),
                                  digits)
                                      )
                               )
        labels
    }
    
    x.break.points <- seq(min(x), max(x), 0.5)
    x.labels <- get.labels(x.break.points, x.orig, x, digits=2)
    p <- p + scale_x_continuous(breaks=x.break.points, 
                                labels=x.labels)
    
    y.break.points <- seq(min(y), max(y), 0.5)
    y.labels <- get.labels(y.break.points, y.orig, y, digits=8)
    p <- p + scale_y_continuous(breaks=y.break.points, 
                                labels=y.labels)
    
    p
    

    Heat map with properly labeled axes

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

Sidebar

Related Questions

Problem This question actually came up at work today. We are planning an experiment
I get this problem while doing some experiment with set . I use a
I have a misterious problem with my first omniauth experiment. I can log in
I have a fairly simple regex problem for a little personal experiment that I
I have the following simple problem that I'd like to use to experiment with
Ok so part two of I have no will power experiment is: Summary Question
here i am again in my self learning hibernate and personal experiment project to
While trying out an experimental UINavigationController-based iPhone application, I ran into a problem when
Problem: I am having trouble implementing a recursive image lazy load in all relevant
problem I'm using LilyPond to typeset sheet music for a church choir to perform.

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.