我正在嘗試創建條形圖或柱形圖來比較參與者之間的前后分數。我設法在折線圖中做到了這一點,但是,我正在努力在條??形圖中將其可視化,有人可以幫助我嗎?
這是我正在使用的資料:
structure(list(Participant = c(2, 3, 5, 7), PRE_QUIP_RS = c(24,
24, 20, 20), POST_QUIP_RS = c(10, 23, 24, 14), PRE_PDQ8 = c(11,
8, 10, 4), POST_PDQ8 = c(7, 7, 9, 4), PRE_GDS = c(1, 7, 1, 0),
POST_GDS = c(1, 4, 2, 0), PRE_PERSISTENT = c(9, 13, 6, 2),
POST_PERSISTENT = c(9, 13, 11, 3), PRE_EPISODIC = c(3, 4,
2, 0), POST_EPISODIC = c(2, 5, 6, 2), PRE_AVOIDANCE = c(6,
3, 0, 2), POST_AVOIDANCE = c(3, 3, 4, 1), PRE_IPQ = c(39,
48, 40, 37), POST_IPQ = c(16, 44, 30, 17), PRE_GSE = c(28,
31, 36, 29), POST_GSE = c(29, 30, 30, 29), PRE_BCI = c(11,
9, 5, 3), POST_BCI = c(3, 15, 0, 0)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -4L))
就我大致希望它的外觀而言,我希望將條形圖放在一起,以便為每個參與者預先和發布,有點像這樣:

uj5u.com熱心網友回復:
你可以試試
library(tidyverse)
df %>%
select(Participant, PRE_QUIP_RS, POST_QUIP_RS) %>%
pivot_longer(cols = c(PRE_QUIP_RS, POST_QUIP_RS), names_to = "group") %>%
mutate(group = str_split(group, "_", simplify = T)[,1],
Participant = as.factor(Participant)) %>%
ggplot(aes(x = Participant, y = value, group = group, fill = group))
geom_col(position = "dodge")

前后訂單
虛擬 %>% 選擇(參與者,PRE_QUIP_RS,POST_QUIP_RS)%>% pivot_longer(cols = c(PRE_QUIP_RS,POST_QUIP_RS),names_to = “group”)%>% mutate(group = str_split(group,“_”,簡化 = T )[,1] %>% factor(., levels = c("PRE", "POST")), # HERE Participant = as.factor(Participant)) %>% ggplot(aes(x = Participant, y =值,組=組,填充=組)) geom_col(位置=“閃避”)

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/523447.html
標籤:rggplot2条形图
上一篇:如何解決群標題被截斷的問題?
