可能有更优雅的方法可以做到这一点,但这里我修改了plot_missing 函数:
plot_missing_smaller_labels <-
function (data, title = NULL, ggtheme = theme_gray(),
theme_config = list(legend.position = c("bottom")))
{
pct_missing <- NULL
missing_value <- profile_missing(data)
output <- ggplot(missing_value, aes_string(x = "feature",
y = "num_missing", fill = "group")) +
geom_bar(stat = "identity") +
geom_text(aes(label = paste0(round(100 * pct_missing, 2), "%")), size = 2) +
scale_fill_manual("Group", values = c(Good = "#1a9641",
OK = "#a6d96a", Bad = "#fdae61", Remove = "#d7191c"),
breaks = c("Good", "OK", "Bad", "Remove")) +
coord_flip() +
xlab("Features") +
ylab("Missing Rows")
class(output) <- c("single", class(output))
plotDataExplorer(plot_obj = output, title = title, ggtheme = ggtheme,
theme_config = theme_config)
}
我在geom_text() 函数中添加了size = 2。
新的plot_missing_smaller_labels函数调用如下:
plot_missing_smaller_labels(df, theme_config=list(axis.text=element_text(size = 6)))
这会提供具有较小文本大小的标签。