我想做一個多色條形圖,但scale_fill_manual或scale_color_brewer等在geom_bar之外或之內都不起作用 -> 請幫幫我吧?
ggplot(data=sust_future。 aes(x=as. factor(`sust.self-perception`))
geom_bar(aes(y = (. .count..)/sum(. .count.)),width=0。 6)
scale_fill_manual(values=c("#999999"/span>。 "#E69F00"/span>。 "#56B4E9")
scale_y_continuous(labels=scales::percent)
實驗室(title = "xxx"。 x = "", y = "")
主題(legend.position = "bottom",
axis.text. x=element_text(size=8), axis.text.
axis.text. y=element_text(size=8))
uj5u.com熱心網友回復:
我不確定你希望條形圖如何著色(例如,基于一列中的因素或基于一些其他條件)。如果你想根據你的資料中的某些內容給geom_bar著色,你必須通過aes(fill = column_name)來定義你想給bar著色的方式,可以在ggplot()中全域定義,也可以在geom_bar()中具體定義。這里有一個例子,你可以嘗試在你的情況下實作(因為我不知道sust_future中的內容):
# global setting。
ggplot(iris, aes(x = Species, 填補= Species))
geom_bar()
scale_fill_manual(values=c("#999999"/span>。 "#E69F00", "#56B4E9"))
# local to geom_bar
ggplot(iris, aes(x = Species)
geom_bar(aes(fill=) operator">= Species))
scale_fill_manual(values=c("#999999"/span>。 "#E69F00", "#56B4E9"))
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/333024.html
標籤:

