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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:25:24+00:00 2026-06-03T13:25:24+00:00

I have the following data frame: id variable value ID1 1A 91.98473282 ID1 2A

  • 0

I have the following data frame:

 id  variable   value
 ID1    1A      91.98473282
 ID1    2A      72.51908397
 ID1    2B      62.21374046
 ID1    2D      69.08396947
 ID1    2F      83.39694656
 ID1    2G      41.60305344
 ID1    2H      63.74045802
 ID1    9A      58.40839695
 ID1    9C      61.10687023
 ID1    9D      50.76335878
 ID1    9K      58.46183206

I’m using ggplot2 to generate a heat map with the data:

     ggplot(data, aes(variable, id)) +
              geom_raster(aes(fill = value)) + 
              scale_fill_gradient(low = "white",
              high = "steelblue")

The plot looks like this:
http://dl.dropbox.com/u/26998371/plot.pdf

I would like for the tiles to fill the plot space on the y-axis rather than leave a space above and below.

I’m sure there is a simple answer. Any help would be greatly appreciated.

scale_y_discrete(expand = c(0, 0)) didn’t work with the y-axis, but scale_x_discrete(expand = c(0, 0)) will work on the x axis to fill the plot space.

  • 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-03T13:25:26+00:00Added an answer on June 3, 2026 at 1:25 pm

    Update It appears that the issue has been resolved in recent versions of ggplot2.

    It’s something to do with there being just one level in the id factor. Change the id factor to numeric, or change the id factor so it has two levels, then the tiles fill the space. Also, coord_equal() with the original id factor will give a long narrow plot, but again filling the space.

    ## Your data
    df = read.table(text = "
    id  variable   value
    ID1    1A      91.98473282
    ID1    2A      72.51908397
    ID1    2B      62.21374046
    ID1    2D      69.08396947
    ID1    2F      83.39694656
    ID1    2G      41.60305344
    ID1    2H      63.74045802
    ID1    9A      58.40839695
    ID1    9C      61.10687023
    ID1    9D      50.76335878
    ID1    9K      58.46183206", header = TRUE, sep = "")
    
    library(ggplot2)
    
     # Change the id factor
     df$id2 = 1                   # numeric
     df$id3 = c(rep("ID1", 5), rep("ID2", 6))      # more than one level
    
     # Using the numeric version
     ggplot(df, aes(variable, id2)) +
              geom_raster(aes(fill = value)) + 
              scale_y_continuous(breaks = 1, labels = "ID1", expand = c(0,0)) + 
              scale_x_discrete(expand = c(0,0)) +
              scale_fill_gradient(low = "white",
              high = "steelblue")
    

    enter image description here

    # Two levels in the ID factor
    ggplot(df, aes(variable, id3)) +
              geom_tile(aes(fill = value)) + 
              scale_fill_gradient(low = "white",
              high = "steelblue") 
    
    # Using coord_equal() with the original id variable
    ggplot(df, aes(variable, id)) +
              geom_tile(aes(fill = value)) + 
              scale_fill_gradient(low = "white",
              high = "steelblue") +
              coord_equal()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following variable and dataframe welltypes <- c(LC,HC) qccast <- data.frame( LC_mean=1:10,
Suppose I have the following data frame: Data1 X1 X2 1 15 1 2
I have the following data test<-data.frame(group=1:10, var.a=rnorm(n=10,mean=500,sd=20), var.b=runif(10)) I would like a barplot with
I have the following data.frames: a <- data.frame(id = 1:3, v1 = c('a', NA,
I have the following data: a=c(1:10) b=c(16:25) c=c(24:33) wa=c(3,7,3,3,3,3,3,3,3,1) wb=c(3,2,3,3,3,3,3,3,3,8) wc=c(4,1,4,4,4,4,4,4,4,1) z=data.frame(a,b,c,wa,wb,wc) I want
I have the following dummy code: dt<-data.frame(country=letters[1:20],val=rnorm(20),siz=rnorm(20)) qplot(x=country,y=val,data=dt,geom=point,size=siz) Now I want to increase the
I'm struggling with the following. If have a (big) data frame with the following:
i have the following data frame dd <- data.frame(b = c(High, Medium, Highest, Low,
I have the following data frame: > str(df) 'data.frame': 3149 obs. of 9 variables:
I have a semi-melted data frame that looks like this: head(final_melt) Group Source 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.