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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:34:56+00:00 2026-05-27T19:34:56+00:00

I have to plot some plot(x,y) scatters, but i would like the points to

  • 0

I have to plot some plot(x,y) scatters, but i would like the points to be color coded based on the value of a continuous variable z.

I would like a temperature palette (from dark blue to bright red). I tried with Rcolorbrewer however the the RdBu palette (which resembles the temperature palette) uses white for the middle values which looks very bad.

I would also like to plot a legend explaining the color coding with a sample of colors and corresponding values.

Any ideas if this can be performed easily in R? No ggplot please!

Season greetings to everybody

  • 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-27T19:34:57+00:00Added an answer on May 27, 2026 at 7:34 pm

    Building off of @BenBolker’s answer, you can do the legend if you take a peek at the code for filled.contour. I hacked that function apart to look like this:

        scatter.fill <- function (x, y, z, 
                                  nlevels = 20, plot.title, plot.axes, 
                                  key.title, key.axes, asp = NA, xaxs = "i", 
                                  yaxs = "i", las = 1, 
                                  axes = TRUE, frame.plot = axes, ...) 
        {
            mar.orig <- (par.orig <- par(c("mar", "las", "mfrow")))$mar
            on.exit(par(par.orig))
            w <- (3 + mar.orig[2L]) * par("csi") * 2.54
            layout(matrix(c(2, 1), ncol = 2L), widths = c(1, lcm(w)))
            par(las = las)
            mar <- mar.orig
            mar[4L] <- mar[2L]
            mar[2L] <- 1
            par(mar = mar)
    
            #Some simplified level/color picking
            levels <- seq(min(z),max(z),length.out = nlevels)
      col <- colorRampPalette(c("blue","red"))(nlevels)[rank(z)]
    
            plot.new()
            plot.window(xlim = c(0, 1), ylim = range(levels), xaxs = "i", 
                yaxs = "i")
      rect(0, levels[-length(levels)], 1, levels[-1L], col = colorRampPalette(c("blue","red"))(nlevels)
            if (missing(key.axes)) {
                if (axes) 
                    axis(4)
            }
            else key.axes
            box()
            if (!missing(key.title)) 
                key.title
            mar <- mar.orig
            mar[4L] <- 1
            par(mar = mar)
    
            #Simplified scatter plot construction
            plot(x,y,type = "n")
            points(x,y,col = col,...)
    
            if (missing(plot.axes)) {
                if (axes) {
                    title(main = "", xlab = "", ylab = "")
                    Axis(x, side = 1)
                    Axis(y, side = 2)
                }
            }
            else plot.axes
            if (frame.plot) 
                box()
            if (missing(plot.title)) 
                title(...)
            else plot.title
            invisible()
        }
    

    And then applying the code from Ben’s example we get this:

    x <- runif(40)
    y <- runif(40)
    z <- runif(40)
    scatter.fill(x,y,z,nlevels = 40,pch = 20)
    

    which produces a plot like this:

    enter image description here

    Fair warning, I really did just hack apart the code for filled.contour. You will likely want to inspect the remaining code and remove unused bits, or fix parts that I rendered non-functional.

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

Sidebar

Related Questions

I have a density plot and I would like to add some summary information
So I'd like to plot simple gamma function, but I have some problems. My
I have a scatter plot with 10 points, some points are above and below
I want to plot some confidence interval graphs in MATLAB but I don't have
I'm using Microsoft's Chart control to plot some series, but if I have no
I have some 3d points I have to plot and since as far as
I have just added a Core Plot view to my application based on a
I have the following code which lets the user plot two points on a
I have two sets of data, (Ax, Ay; Bx, By). I'd like to plot
I have 40 subjects, of two groups, over 15 weeks, with some measured variable

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.