1

I'm working with the likert package and can successfully generate a plot depicting my choice data. I also know how to manually specify fill colors. However, I'd like to add an outline to the bars to make them pop a little bit more. Any ideas?

Here is some sample code:

p = plot(lk, plot.percents=FALSE, plot.percent.low=FALSE, plot.percent.high=FALSE, plot.percent.neutral=FALSE, group.order=c("MJ", "ASM", "Both", "Both."), legend.position='right') + theme(axis.text.x=element_text(colour="black", size=12)) + theme(axis.text.y=element_text(colour="black", size=12))+ggtitle("B") + theme(plot.title=element_text(hjust=0)) + scale_fill_manual(values=c("gray86", "dark grey"), name="Preference")
RSchaeffer
  • 41
  • 4

1 Answers1

3

One way is to use update_geom_defaults() (using likert demo data since you didn't provide any):

library(likert)
library(viridis)
library(ggplot2)

data(pisaitems)
items29 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST25Q']
names(items29) <- c("Magazines", "Comic books", "Fiction", 
                    "Non-fiction books", "Newspapers")
l29 <- likert(items29)

update_geom_defaults("bar", list(colour="white", size=0.15))

p <- plot(l29, 
         plot.percents=FALSE,
         plot.percent.low=FALSE, 
         plot.percent.high=FALSE, 
         plot.percent.neutral=FALSE, 
         legend.position='right')
p <- p + ggtitle("B")
p <- p + theme(axis.text.x=element_text(colour="black", size=12))
p <- p + theme(axis.text.y=element_text(colour="black", size=12))
p <- p + theme(plot.title=element_text(hjust=0)) 
p <- p + scale_fill_viridis(discrete=TRUE) 
p

enter image description here

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
  • That worked perfectly. Thanks! And yes, your presentation of code is much cleaner. I've taken note for future posting. – RSchaeffer May 03 '16 at 14:45
  • If you want to keep the ordering, use the `color` option on `plot()`, as per https://stackoverflow.com/questions/54745479/colors-rearranges-x-axis-in-likert-how-do-i-avoid-this – Carrol Oct 19 '22 at 20:57