這是我的資料的一個小樣本,只是為了展示感興趣的情節
df<-read.table (text=" P U W
A F F
M M F
N F F
A F F
M M F
N M F
Q M F
Q M F
R F M
R F M
", header=TRUE)
我想在 ggplot2 中獲得以下情節

條形頂部的圖和數字不正確。我只是想展示感興趣的情節。如果可能,請不要使用回圈。
uj5u.com熱心網友回復:
鑒于問題缺乏細節和特異性,我無法確定您在尋找什么。也許是這樣的。
library(tidyverse)
df<-read.table (text=" P U W
A F F
M M F
N F F
A F F
M M F
N M F
Q M F
Q M F
R F M
R F M
", header=TRUE)
x <- df %>%
mutate(across(c(U, W), ~paste0(cur_column(), .x))) %>%
pivot_longer(names_to = "series",
values_to = "group",
cols = c(U, W)) %>%
group_by(group, P) %>%
summarise(n = n())
#> `summarise()` has grouped output by 'group'. You can override using the
#> `.groups` argument.
x %>%
ggplot(aes(x = P, y = n, fill = P))
geom_col()
geom_text(aes(label = n),
vjust = -0.1)
scale_y_continuous(expand = expansion(mult = c(0, 0.1)))
facet_wrap(~group)

Created on 2022-03-10 by the reprex package (v2.0.1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/443275.html
上一篇:ggplot2餅圖:可以通過將ggrepel切片標簽移向餅圖的圓周來重新定位它們嗎?
下一篇:自定義意大利面條情節
