Try   HackMD

R超好用選色套件_cols4all_修改ggplot2配色

LHB阿好伯, 2021/07/16

tags: R

安裝cols4all套件

# install.packages("devtools") #install.packages("kableExtra") remotes::install_github("mtennekes/cols4all") library(cols4all)

執行c4a_gui()啟動GUI(Shiny APP)來查看和分析調色板

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

選擇顏色

選擇調色板非常簡單只需要使用c4a("調色板名稱","顏色數量")指定調色板名稱與顏色數量

# 在"accent"調色板選擇 3 種顏色 c4a("accent",3)

[1] "#7FC97F" "#BEAED4" "#FDC086"

ggplot2使用範例

簡單繪製一個範例來演示

library(ggplot2) p1 <- ggplot(iris,aes(x = Sepal.Length, y = Sepal.Width))+ geom_point(aes(col = Species))+ theme_bw() p1

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

p1 + scale_color_manual(values=c4a("accent",3))

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

p1 + scale_color_manual(values=c4a("green_orange",3))

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

參考資料

🌟全文可以至下方連結觀看或是補充

全文分享至

https://www.facebook.com/LHB0222/

https://www.instagram.com/ahb0222/

有疑問想討論的都歡迎於下方留言

喜歡的幫我分享給所有的朋友 \o/

有所錯誤歡迎指教

全部文章列表

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →