# 在使用ggplot2有時(shí)會(huì)遇到想要在橫縱坐標(biāo)上加入特定的值,滿足說明的需要
scale_y_continuous(breaks=c(seq(from=0,to=150,by=50), 20)) 可自主設(shè)置breaks為想要的分割
# 更改某個(gè)橫縱坐標(biāo)軸標(biāo)簽的顏色
library(ggtext)
library(glue)
highlight = function(x, pat, color="black", family="") {
ifelse(grepl(pat, x), glue("<b style='font-family:{family}; color:{color}'>{x}</b>"), x)
}
scale_x_discrete(labels=function(x) highlight(x, "setosa", "purple")) +
scale_color_manual(values = ifelse(df$Species=="setosa","red","black"))
# 更改圖例標(biāo)題
guides(color=guide_legend(title="Method"))
guides(fill=guide_legend(title="Method"))
此文章參考:
https://stackoverflow.com/questions/68839059/changing-specific-value-color-with-ggplot
https://stackoverflow.com/questions/14622421/how-to-change-legend-title-in-ggplot