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

  • Home
  • SEARCH
  • 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 6920075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:06:06+00:00 2026-05-27T10:06:06+00:00

I am trying to produce a heat map using ggplot2. I found this example

  • 0

I am trying to produce a heat map using ggplot2. I found this example, which I am essentially trying to replicate with my data, but I am having difficulty. My data is a simple .csv file that looks like this:

people,apple,orange,peach
mike,1,0,6
sue,0,0,1
bill,3,3,1
ted,1,1,0

I would like to produce a simple heat map where the name of the fruit is on the x-axis and the person is on the y-axis. The graph should depict squares where the color of each square is a representation of the number of fruit consumed. The square corresponding to mike:peach should be the darkest.

Here is the code I am using to try to produce the heatmap:

data <- read.csv("/Users/bunsen/Desktop/fruit.txt", head=TRUE, sep=",")
fruit <- c(apple,orange,peach)
people <- data[,1]
(p <- ggplot(data, aes(fruit, people)) + geom_tile(aes(fill = rescale), colour = "white") +    scale_fill_gradient(low = "white", high = "steelblue"))

When I plot this data I get the number of fruit on the x-axis and people on the y-axis. I also do not get color gradients representing number of fruit. How can I get the names of the fruits on the x-axis with the number of fruit eaten by a person displayed as a heat map?
The current output I am getting in R looks like this:

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-27T10:06:06+00:00Added an answer on May 27, 2026 at 10:06 am

    To be honest @dr.bunsen – your example above was poorly reproducable and you didn’t read the first part of the tutorial that you linked. Here is probably what you are looking for:

     library(reshape)
     library(ggplot2)
     library(scales)
    
     data <- structure(list(people = structure(c(2L, 3L, 1L, 4L), 
                                               .Label = c("bill", "mike", "sue", "ted"), 
                                               class = "factor"), 
                            apple = c(1L, 0L, 3L, 1L), 
                            orange = c(0L, 0L, 3L, 1L), 
                            peach = c(6L, 1L, 1L, 0L)), 
                        .Names = c("people", "apple", "orange", "peach"),
                        class = "data.frame", 
                        row.names = c(NA, -4L))
     data.m <- melt(data)
     data.m <- ddply(data.m, .(variable), transform, rescale = rescale(value))
     p <- ggplot(data.m, aes(variable, people)) + 
             geom_tile(aes(fill = rescale), colour = "white") 
     p + scale_fill_gradient(low = "white", high = "steelblue")
    

    enter image description here

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

Sidebar

Related Questions

I'm trying to produce a line chart using Flot, but I want the data
I am trying to produce some example graphics using ggplot2, and one of the
I'm trying to produce random integers (uniformly distributed). I found this snippet on an
I trying to produce a DockLayoutPanel which looks like the example in the Developer's
In this code example, i am trying to produce the following view hierarchy Window
This is making me feel dumb, but I am trying to produce a single
I'm trying to produce a plot with two lines using data taken from stdin.
I'm trying to make a heat map for a data set that includes negative
I'm trying to produce sheets of photographs with captions arranged in a grid using
I'm trying to produce a report that has multiple grouping but does not just

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.