0

I'm plotting some Likert data as diverging stacked barcharts, but I can't figure out how to draw borders around the keys in the legend in auto.key (showing colors for each Likert item); HH is based on lattice, so to draw orders around the bars in the actual plots is no problem (see the "# <-" command in the code below).

So how do can I draw (black) borders around keys in the HH package (or make some sort of lattice workaround)?

Here's an equivalent to the code I'm using, with data from the "ProfChal" table often used in HH examples:

data("ProfChal")
likert(Question ~ . , ProfChal[ProfChal$Subtable=="Employment sector",],
       ylab=NULL,
       main = "",
       auto.key = list(columns = 1, reverse.rows = T),
       as.percent = T,
       borders = list()) # <- This draws borders around the bars in the plot

This code makes the plot below, but I want to have borders also where the bottom arrow points. (Drawing borders around barchart keys seems to be default in lattice ...)

enter image description here

persboe
  • 71
  • 1
  • 5

1 Answers1

0

I stumbled upon the solution to the above problem in the HH-package documentation, which sort of illustrates the lack of reader-friendlyness in some of these R package documentations ...

One can add rect= list(col= col, border = "black")) inside the auto.key. However, it seems one has to explicitly specify the colors of the keys; if one only writes border = "black", the whole key will be black ...

See the solution in the code below.

 data("ProfChal")
 likert(Question ~ . , ProfChal[ProfChal$Subtable=="Employment sector",],
       ylab=NULL,
       main = "",
       col=c("#E94E1B", "#F7AA4E", "grey", "#6193CE", "#00508C"), # <- Specify colors (for bars in the plot)
       auto.key = list(columns = 1,reverse.rows = T,
                    reverse.rows = T,
                    rect= list(col=c("#E94E1B", "#F7AA4E", "grey", "#6193CE", 
                    "#00508C"), # <- Specify colors again (for keys)
                    border = "black")), # <- Adds border around the keys
       as.percent = T,
       borders = list())

The above code makes the plot below (though with other colors than in the original plot):

enter image description here

persboe
  • 71
  • 1
  • 5