背景:我正在plotly通過ggplotly()函式中的工具提示準備互動式繪圖。創建工具提示資訊的推薦作業流程是在 ggplot 圖中添加一個未知的 aestetic,然后在ggplotly()函式的后面使用這個未知的 aestetic。
問題:添加未知的 aestetic 會破壞填充變數的順序。有解決方法嗎?
附加資訊:這個表示可以通過讓ggplot通過計數來解決geom_bar()。但是,這不適用于我的實際問題。
library(dplyr)
library(ggplot2)
a <- diamonds %>%
group_by(color, cut, clarity) %>%
summarise(n = n()) %>%
ggplot(aes(x = color, y = n, fill = cut))
geom_col()
#> `summarise()` has grouped output by 'color', 'cut'. You can override using the `.groups` argument.
b <- diamonds %>%
group_by(color, cut, clarity) %>%
summarise(n = n()) %>%
ggplot(aes(x = color, y = n, fill = cut))
geom_col(
aes(text = paste("Count:", n))
)
#> `summarise()` has grouped output by 'color', 'cut'. You can override using the `.groups` argument.
#> Warning: Ignoring unknown aesthetics: text
a

b

由
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/446304.html
