# 在使用ggplot2有时会遇到想要在横纵坐标上加入特定的值,满足说明的需要
scale_y_continuous(breaks=c(seq(from=0,to=150,by=50), 20)) 可自主设置breaks为想要的分割
# 更改某个横纵坐标轴标签的颜色
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"))
# 更改图例标题
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