簡體   English   中英

在ggplot條形圖中更改顏色

[英]change color in ggplot bar chart

我對 r 還是新手,希望能在我的一個情節上得到幫助。 我正在嘗試為該圖表添加一些顏色,正在尋求幫助。 我的陰謀 我相信應該包括圖像,任何提示都會有所幫助。 我不是在尋找任何具體的東西,而是關於如何為條形着色或勾勒出它們的輪廓,甚至為背景着色的任何建議。 謝謝你的幫助!

代碼:

 WorldCupMatches %>%
   filter(Year == "2014", Home.Team.Name %in% top10teams_in_order) %>%
   ggplot(aes(x = Home.Team.Name, y = Home.Team.Goals)) +
   geom_col()

如果您沒有特定的 colors,請檢查RColorBrewer package。 它有許多組 colors 對色盲觀眾來說是安全的。

library(RColorBrewer)

 WorldCupMatches %>%
   filter(Year == "2014", Home.Team.Name %in% top10teams_in_order) %>%
   ggplot(aes(x = Home.Team.Name, y = Home.Team.Goals)) +
   geom_col(fill = brewer.pal(10,"Set3")) + # 10 colors one for each bar
   theme_bw() + # set general look
   theme(panel.grid.major.x=element_blank()) # remove horizontal gridlines

如果你想引起對一個欄的注意,你可以像這樣選擇特定的 colors

# 7 gray, then 1 red, then 2 gray
geom_col(fill = c(rep("gray", 7), "red", rep("gray", 2))) +  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM