Your viz[,3:5] <- map(viz[,3:5], scales::percent) makes the values to a character class, but it needs to be numeric. There is no need to convert it to percent in advance; just use the scales function in
scale_y_continuous(labels=scales::percent)
. See below
library(tidyverse)
#> Registered S3 methods overwritten by 'ggplot2':
#> method from
#> [.quosures rlang
#> c.quosures rlang
#> print.quosures rlang
devtools::install_github("dgrtwo/drlib")
#> Skipping install of 'drlib' from a github remote, the SHA1 (2be33ab6) has not changed since last install.
#> Use `force = TRUE` to force installation
library(drlib)
viz <- data.frame(type = c(rep("A",5),rep("B",4)),
project = c("ABC","BCD","CDE","EFG","FGI","GIK","IKL","KLM","LMO"),
complexity = c(.8,.95,.6,.8,.9,.3,.7,.2,.6),
impact = c(1,.8,.7,.8,.9,.4,.8,.6,.5),
relevance = c(.8,.5,.7,.9,.1,.8,.7,.7,.8),
stringsAsFactors = F)
## Convert to percentage
#viz[,3:5] <- map(viz[,3:5], scales::percent)
viz_lng <- viz %>%
gather(-c(1,2), key = category, value = importance)%>%
arrange(desc(importance))
ggplot(viz_lng[which(viz_lng$importance>0),],
aes(x = reorder_within(project, importance, category, ),
y= importance, group = project, fill = project)) +
geom_bar(stat="identity") +
scale_x_reordered() +
scale_y_continuous(label=scales::percent)+
facet_wrap(vars(category, type), scales="free_x", ncol=2) +
guides(fill=FALSE) + theme_bw() +
theme(strip.text = element_text(size = 14),
axis.text.x = element_text(angle = 45, hjust = 1),
legend.title = element_blank(),
axis.text = element_text(size = 14),
axis.title = element_text(size = 14))
