2

I am trying to create competency level heatmap for a manufacturing plant.I have tried both the HEATMAP as well as GGPLOT. I have couple of questions when it comes to using GGPLOT- here is the sample data. I am still not sure which will yield me the best result.

GROUP       ProcessName        EmployeeName    Level  
Furnace     Machining           Alex             4  
Furnace     Machining           Bobby            1  
Furnace     Milling             Alex             3  
Repair      Heat                Chris            2  
Repair      Heat                Bobby            3  

Basically the data will have competency level of 100 of employees with different process and groups. I would like to show a heatmap of the entire manufacturing and also by groups and if possible by shifts which are in one more column.

so far I have tried HEATMAP, HEATMAP.2 - I am missing something but I am not getting what I wanted here

So I went with GGPLOT ,

ggplot(test_data, aes(factor(Name),factor(ProcessName),factor(level)) +
    geom_tile() +
    theme(axis.text.x = element_text(angle=45, hjust = 1,vjust=1,face = "bold"),) 

In the resulting plot, the squares are coloured in all places.

I am looking for

  1. Where each square is coloured based on the level
  2. specific colours for each level ( here I tried scale_color_manual - but it's not changing)
  3. one square for the employee and that particular process.

Please suggest if I need to look at anything different.

Richard Telford
  • 9,558
  • 6
  • 38
  • 51
Neo
  • 67
  • 5
  • you need to use `fill = level` in the `aes` – Richard Telford Aug 05 '20 at 17:59
  • i did try that and still the boxes that are colored are not properly structured, for e.g if i look at the box for the combination of Name and Process - the fill color is only one quarter of that rectangle – Neo Aug 05 '20 at 20:25

1 Answers1

0

This works for me.

You only need to make the ProcessName etc into a factor if you want to change the order, and that is probably best done before the ggplot.

You can change the fill with one of the scale_fill_* functions.

library("tidyverse")
test_data <- read_table(
"GROUP       ProcessName        EmployeeName    Level  
Furnace     Machining           Alex             4  
Furnace     Machining           Bobby            1  
Furnace     Milling             Alex             3  
Repair      Heat                Chris            2  
Repair      Heat                Bobby            3")  


ggplot(test_data, aes(x = EmployeeName, y = ProcessName, fill = Level)) +
   geom_tile() +
   theme(axis.text.x = element_text(angle=45, hjust = 1, vjust=1, face = "bold")) 

Created on 2020-08-05 by the reprex package (v0.3.0)

Richard Telford
  • 9,558
  • 6
  • 38
  • 51
  • Thanks Richard - in the above image if you see i would Alex and Heat represented by 1 square , similarly a box for Name and Process Name and color that box --can ggplot do that – Neo Aug 05 '20 at 20:42
  • Richard Telford : Basically i am looking to color the boxes/tiles/squares for the specific combination of Name and Process Name - so in the plot above the First box should represent Alex and Heat , second box would be bobby and Heat..so on and so forth - how do i do that in ggplot is where i am struggling with – Neo Aug 05 '20 at 20:51
  • You can turn the background grid off if you don't want it. Add `theme(panel.grid = element_blank()) ` – Richard Telford Aug 05 '20 at 22:14
  • Thanks Richard - i have too many employee names and process names and they make the plot crowded on the x-axis labels - is there an easy way to do this – Neo Aug 05 '20 at 23:59
  • Turning the labels to vertical helps, then you can reduce the font size or make the plot bigger, but if you really have too many, you need to either make multiple plots or drop the names (perhaps show by department) – Richard Telford Aug 06 '20 at 09:17