I have a four-point Likert scale that I would like to stack by an ordered color palette that I have made (likert_palette), but there is always one side that is not ordered. Are there anyone with a solution on how to get the darkest red on the utmost left? The categories are of type factor and is ordered accordingly, and two of the categories have negative values and the other two positive values.
likert_palette = c("#F58C7B","#F9B8AD","#A0DCB3","#67C785")
fivelevels <- c("Substantially less often",
"Somewhat less often",
"Unchanged",
"Somewhat more often",
"Substantially more often"
)
Here in the example I have only one type of activity in the data frame, but there are several more in the original.
df <- cbind("activities"=c("Online lectures"),
"x"=c("Substantially less often",
"Somewhat less often",
"Somewhat more often",
"Substantially more often"),
"prosent"=c(-0.02,-0.05, 0.32,0.42)) %>%
as_tibble() %>%
mutate(prosent = as.double(prosent),
x = factor(x, levels = fivelevels))
Here it becomes tricky whenusing: reverse = T only reverse the color order for the positive values, but not the negative ones. So the green colors are
df %>%
ggplot(aes(y = reorder(activities, desc(activities)), x = prosent, fill= x)) +
# geom_col(position = position_stack (reverse = F)) +
geom_col(position = position_stack (reverse = T)) + #HERE
geom_text(aes( x = prosent, label = scales::percent(prosent, accuracy = 1L)),
position = position_stack( reverse = T, vjust = 0.5), size = 2) +
scale_fill_manual(values = likert_palette)
Thanks for the help!