|
|
- gglegend<-function(data, x, y, var, stat="median", color="black", ...){
- if (stat == "median"){
- data<-data %>% group_by({{var}}) %>% summarise("{{x}}":=median({{x}}, na.rm=T), "{{y}}":=median({{y}}, na.rm=T))
- }
- if (stat == "mean"){
- data<-data %>% group_by({{var}}) %>% summarise("{{x}}":=mean({{x}}, na.rm=T), "{{y}}":=mean({{y}}, na.rm=T))
- }
- if (!is.null(color)){
- return(geom_label(data = data, aes({{x}},{{y}}, label={{var}}), color=color, ...))
- }else{
- return(geom_label(data = data, aes({{x}},{{y}}, label={{var}}),...))
- }
- }
|