使用drlib软件包将条形图排列在每个网格级别上。 但是,它似乎适用于facet_wrap,但不适用于网格,因为找到了空条。
有办法摆脱空条吗? 类似问题(非R): How can i remove empty bars from dc.js row chart, whenever the dimension is null or empty, there appears an empty bar on row chart
Remove empty bars from grouped barplot
library(tidyverse)
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)
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() +
facet_grid(vars(category), vars(type), scales="free_x") +
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))
预期结果将是排列有条形,但是在每个网格级别都看不到空条形。