有沒有辦法顯示未觀察到的集合ggupset?
代表
B在這個例子中,即使沒有觀察到,我也想展示。
library(ggplot2)
library(ggupset)
df <- data.frame(x = I(list(c("A", "C"),
"A",
"C")))
df %>%
ggplot(aes(x = x))
geom_bar(stat = 'count')
scale_x_upset()

嘗試
# manually give sets (does not work)
df %>%
ggplot(aes(x = x))
geom_bar(stat = 'count')
scale_x_upset(sets = LETTERS[1:3])
# add to data, but do not show (does not work)
df %>%
tibble::add_row(x = list("B")) %>%
ggplot(aes(x = x))
geom_bar(stat = 'count')
scale_x_upset(n_sets = 2)
預期產出
如果能夠對集合標簽進行排序以顯示 A、B、C 而不是 A、C、B,那就太好了。

uj5u.com熱心網友回復:
axis_combmatrix如果您首先將串列元素連接到一個帶有您選擇的分隔符的標準字符列中,則可以使用:
df %>%
within(x <- sapply(x, paste, collapse = "_")) %>%
ggplot(aes(x = x))
geom_bar(stat = 'count')
axis_combmatrix(sep = "_", levels = c("A", "B", "C"))

您可以在此處設定您喜歡的任何級別順序:
df %>%
within(x <- sapply(x, paste, collapse = "_")) %>%
ggplot(aes(x = x))
geom_bar(stat = 'count')
axis_combmatrix(sep = "_", levels = c("A", "C", "B"))

轉載請註明出處,本文鏈接:https://www.uj5u.com/net/536946.html
標籤:r图表2心烦意乱
下一篇:GGplot列不存在
