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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:54:06+00:00 2026-05-28T00:54:06+00:00

After studying Hadley’s book and searching here on SO I have created a heatmap

  • 0

After studying Hadley’s book and searching here on SO I have created a heatmap consisting of a matrix of years and months, with the colour varying according the percentage change in a time series variable. The heatmap and the code I used to get it are shown below. I have a few remaining questions that I haven’t been able to resolve on my own.

1) How can I sort/order the matrix so that the years in the y-axis run from the earliest to the latest? In this case I want the years to start from the top at 1995 and continue to 2011 at the bottom of the y-axis.

2) I want every year to be shown on the y-axis but instead it is showing only every 5th year. I thought that the scale_y_date in my code would deal with this but it seems to have no affect. How can I force the y-axis to display each year?

3) I suspect this is still on the ggplot2 “to do” list, but is there any way to make the x-axis labels (in this case the Jan, Feb, Mar, Apr etc) display at the top of the plot rather than at the bottom?

require(ggplot2)
mydf <- data.frame(date=seq(as.Date("1995/1/1"), by="month", length.out=203),yoy=runif(203, min=-1, max=1))
p_heat <- ggplot(mydf, aes(x=month(date,label=TRUE),y=year(date), fill = yoy, label = sprintf("%1.1f%%", 100*yoy),size=10)) + 
  scale_y_date(major="years", format="%Y") +
  geom_tile() + geom_text(aes(size=10)) +
  scale_fill_gradient2(low = "red", high = "green") +
  scale_x_discrete(expand=c(0,0)) +
  scale_y_continuous(expand=c(0,0)) +
  opts(title="Value (%)") +
  opts(panel.grid.minor=theme_blank()) +
  opts(axis.ticks = theme_blank()) +
  opts(panel.grid.major=theme_blank()) +
  opts(axis.title.y = theme_blank()) +
  opts(axis.title.x = theme_blank()) +
  opts(legend.position = "none")
p_heat

enter image description here

  • 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-28T00:54:07+00:00Added an answer on May 28, 2026 at 12:54 am

    For the first two points, you can replace scale_y_continuous with scale_y_reverse to have the earliest years on top, and explicitly specify the breaks and labels.

    p_heat +  scale_y_reverse(breaks=1995:2011, labels=1995:2011, expand=c(0,0) )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After studying Miles Jones cupcake forum plugin, I have a couple of questions here:
After some studying, I created a small app that calculates DFTs (Discrete Fourier Transformations)
After spending a couple months studying DDD methodology, I've now began to apply these
I have been working with JQM for a couple of weeks and after studying
I look after a large site and have been studying other similar sites. In
So after a few years of inactivity after studying at uni, I'm trying to
After studying TCP/UDP difference all week, I just can't decide which to use. I
Even after studying the examples , I'm having trouble figuring out how to extract
After deploying WCF server (svc) on my Server, I have got this message when
I'm designing a new web project and, after studying some options aiming scalability, 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.