1

I have the following graph using library(waffle)

enter image description here

My problem is that the last name group does not appear. the code that I am using is the following

counts<-c(135.92, 15.98, 14.97, 14.15, 5.82, 11.82, 0.07 )
counts_names<-sprintf("%s (%s)", c("Coal", "Gas", "Wind", "Hydro", "Grid-scalar solar", "Rooftop solar", "Storage systems"), 
                  scales::percent(round(counts/sum(counts), 4)))
names(counts)<-counts_names
Generation_graph<-waffle(counts)+ scale_fill_tableau(name=NULL)

How can i get my original graph with the seven groups at the right

UPDATE: Reading one of the comments I noticed that including the option labels enable me keep my original graph with all the names.

Generation_graph<-waffle(counts)+ scale_fill_tableau(name=NULL, labels=counts_names)
Eve Chanatasig
  • 397
  • 2
  • 10

2 Answers2

2

The issue is that the value of your seventh category is simply to small to show up in the plot. The last non-labbeled group simply reflects the "squares" added by waffle by default to "fill up" the last column.

Depending on what you are trying to achive there are several options to go:

library(waffle)
#> Loading required package: ggplot2
library(ggthemes)

counts<-c(135.92, 15.98, 14.97, 14.15, 5.82, 11.82, 0.07)
counts_names<-sprintf("%s (%s)", c("Coal", "Gas", "Wind", "Hydro", "Grid-scalar solar", "Rooftop solar", "Storage systems"), 
                      scales::percent(round(counts/sum(counts), 4)))
names(counts)<-counts_names
  1. You can set the colors via the colors argument. In that case the last category will show up in the legend but not in the plot. Also. In that case the last column is not filled up.
waffle(counts, colors = tableau_color_pal()(length(counts)))

  1. Instead of using the raw data you can use the ceiling(). In that your last category is reflected both in the plot and in the legend.
waffle(ceiling(counts), colors = tableau_color_pal()(length(counts)))

  1. Finally if you the last column to be filled up you can use ceiling(), let waffle chosse the colors and ovveride with scale_fill_manual:
waffle(ceiling(counts)) + scale_fill_tableau()

stefan
  • 90,330
  • 6
  • 25
  • 51
0

You can use the scale_fill_manual() to get what you are looking for

library(ggthemes)
library(waffle)
counts<-c(135.92, 15.98, 14.97, 14.15, 5.82, 11.82, 0.07 )
counts_names<-sprintf("%s (%s)", c("Coal", "Gas", "Wind", "Hydro", "Grid-scalar solar", "Rooftop solar", "Storage systems"), 
                      scales::percent(round(counts/sum(counts), 4)))
names(counts)<-counts_names
Generation_graph<-waffle(counts) + 
  scale_fill_manual(values = c("red", "blue", "green", "purple", "pink", "yellow", "orange", "blue"),
                    labels = counts_names, 
                    drop = TRUE)

enter image description here

Daniel_j_iii
  • 3,041
  • 2
  • 11
  • 27