我想制作一個條形圖,其中每個條都由該資料框中的三列之一表示。每個條的“大小”取決于 adorn_totals 創建的總和。
可重現的例子:
library(janitor)
test_df <- data.frame(
a = c(1:5),
b = c(1:5),
c = c(1:5)
) %>%
adorn_totals(where = 'row', tabyl = c(a, b, c))
我嘗試了以前發布的解決方案,但是沒有用:鏈接到帖子:
uj5u.com熱心網友回復:
沒有兩種pivot_longer選擇janitor::adorn_totals()
#uses the internal weight stat to calculate the sum
#geom_bar only uses one aesthetic (x OR y)
data.frame(a = c(1:5), b = c(1:5), c = c(1:5)) %>%
pivot_longer(everything()) %>%
ggplot(aes(name, weight=value))
geom_bar()
#geom_col version
#Lots of flexibility in summarise:
data.frame(a = c(1:5), b = c(1:5), c = c(1:5)) %>%
pivot_longer(everything()) %>%
group_by(name) %>%
summarise(total=sum(value)) %>%
ggplot(aes(name, total))
geom_col()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/529057.html
