簡體   English   中英

數據使用缺少的圖標簽文本大小

[英]Data labels text size using plot missing

我使用函數plot_missing來顯示我的數據集中的NA數。 由於我的數據集有50個變量,我需要調整文本大小。 我設法更改了軸的文本大小,但沒有更改數據標簽的文本大小。 有什么建議么?

使用樣本數據集:

library(ggplot2)
library(DataExplorer)

df <- data.frame(matrix(data=runif(1000, 0, 100), ncol=50))
df[df>80] <- NA

plot_missing(df, theme_config =list(axis.text=element_text(size=6)))

可能有更優雅的方法來做到這一點,但在這里我修改了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)))

這為標簽提供了更小的文字大小。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM