如何在 R 或 ggplot2 中绘制类似矩阵的小数据

问题描述 投票:0回答:1

我有一个像下面的

DATA
这样的小矩阵,其中对于变量
Challenge
的每一行,后续列上都有一个count,显示有多少人对此做出了从“我不知道”到“非常具有挑战性”的回答挑战。

目标是在所有挑战的情节上显示这些计数。

我想知道R或ggplot2中是否有绘图函数可以在单个图中表示这些数据?

DATA <- structure(list(Challenge = c("Obtaining  documents from the student's previous school2", 
"Authenticating obtained documents 2", "Translating the documents into English2", 
"Conducting schooling history interviews or other methods to obtain non-transcript course history information2", 
"Administering assessment for placement or proficiency-based credit2", 
"Evaluating course equivalency; what credit will be awarded for prior work2", 
"Making placement decisions", "Lack of clarity around process, practices, roles, or responsibilities", 
"Your own understanding of what is recorded on the transcript"
), `I don't know` = structure(c(16L, 32L, 20L, 22L, 32L, 17L, 
15L, 18L, 11L), dim = 9L, class = "table", dimnames = list(NULL)), 
    `Not at all challenging` = structure(c(7L, 20L, 46L, 27L, 
    28L, 22L, 21L, 34L, 47L), dim = 9L, class = "table", dimnames = list(
        NULL)), `Somewhat challenging` = structure(c(86L, 67L, 
    85L, 80L, 64L, 93L, 110L, 65L, 90L), dim = 9L, class = "table", dimnames = list(
        NULL)), `This is not a part of our process` = structure(c(2L, 
    12L, 1L, 18L, 31L, 8L, 6L, 1L, NA), dim = 9L, class = "table", dimnames = list(
        NULL)), `Very challenging` = structure(c(69L, 49L, 28L, 
    33L, 25L, 40L, 28L, 62L, 32L), dim = 9L, class = "table", dimnames = list(
        NULL))), class = "data.frame", row.names = c(NA, -9L))
r dataframe function ggplot2 plot
1个回答
0
投票

在我看来,小的倍数图是最好的:

library(ggplot2)
library(dplyr)
library(tidyr)

DATA |>
  dplyr::mutate(across(-Challenge, as.integer)) |>
  tidyr::pivot_longer(
    cols = -Challenge,
    names_to = "name", 
    values_to = "value", 
    ) |>
  View() 
  ggplot(aes(y = name, x = value)) +
  geom_col() +
  facet_wrap(~Challenge) 
© www.soinside.com 2019 - 2024. All rights reserved.