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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:30:21+00:00 2026-05-27T20:30:21+00:00

I have an R / ggplot2 use case that seems to call for geom_raster

  • 0

I have an R/ggplot2 use case that seems to call for geom_raster: a regular Cartesian grid with z-values at x, y locations. I’ve been using geom_tile, and I expected a performance improvement from switching to geom_raster. But I don’t seem to be seeing one…

Here’s a toy example (but about the right size), using base graphics:

n <- m <- 200
x <- 1:n
y <- 1:m
f <- function(x, y) 10 * sin(x / n) * cos(y / m)
z <- outer(x, y, f)
system.time(image(z))

   user  system elapsed 
  0.998   0.007   1.023 

Here it is with ggplot2:

obs <- expand.grid(x=x, y=y)
obs$z <- as.numeric(as.list(z))
require(ggplot2)
p <- ggplot(obs, aes(x=x, y=y, fill=z))
system.time(show(p + geom_tile()))

   user  system elapsed 
  7.328   0.891   8.187 

require(ggExtra)
system.time(show(p + geom_raster()))

   user  system elapsed 
  7.000   0.637   7.799

So, a modest gain, but nowhere near what I was expecting. Am I doing it wrong? Many thanks in advance!

  • 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-27T20:30:21+00:00Added an answer on May 27, 2026 at 8:30 pm

    You should use geom_raster from the latest ggplot2 (dev version, currently), not the buggy prototype in ggExtra (this package is now deprecated, btw).

    Doing so, I get better results, 4.705 vs. 1.416 (elapsed). Quite an improvement.

    Edit: it turns out that ?geom_raster in ggplot2 already offers a better benchmark, on my system

    benchplot(base + geom_raster())
           step user.self sys.self elapsed
    1 construct     0.006    0.004   0.010
    2     build     0.887    0.212   1.109
    3    render     0.449    0.119   0.584
    4      draw     0.108    0.005   0.141
    5     TOTAL     1.450    0.340   1.844
    > benchplot(base + geom_tile())
           step user.self sys.self elapsed
    1 construct     0.016    0.005   0.026
    2     build     1.031    0.329   1.365
    3    render     1.021    0.297   1.318
    4      draw     0.987    0.041   1.040
    5     TOTAL     3.055    0.672   3.749
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following data set that I am trying to plot with ggplot2,
I'm plotting a group of curves, using facet in ggplot2. I'd like to have
Let's say I have a list of plots that I've created. library(ggplot2) plots <-
I have created a graph using ggplot2. Now I want to have the legend
I have the following ggplot2 code that plots the ribbon from the 3rd to
I have found the function dhist() in the ggplot2 package that implements the variable
I have a scatter plot in R (with ggplot2). The data has a numeric
I have a couple of questions regarding facetting in ggplot2... Let's say I have
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I

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.