Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change "a" in geom_label_repel in R to something else and not just delete it

Tags:

r

ggplot2

I am trying to change (not to remove) the "a" that gets displayed by geom_label_repel in the legend. I already found the following Thread: Why does text appear in the legend? that told me how to remove it.

library(ggrepel)

data <- data.frame(xVal,yVal, stringsAsFactors = FALSE)    
plot <- ggplot(data, aes(x=xVal, y=yVal)) +
      geom_point() + 
      geom_label_repel( aes( label=pointName, fill=factor( yVal ) ), nudge_x = 1.25, nudge_y = 1.2 ) +
      scale_fill_manual(values=colorPallet, labels = yVal) 

This Code gives me the following image: enter image description here

I want to change it so that the "a" in the legend is displaying the numbers i have in the vector pointName. (that are the numbers in the nicture that range from 48 to 96).

Thank you all.

like image 258
uv239 Avatar asked Sep 05 '25 08:09

uv239


1 Answers

"Guides for geom_text() now accept custom labels with guide_legend(override.aes = list(label = "foo")) (@brianwdavis, #2458)."

As per release 3.0.0.

So here you'd use scale_fill_manual(values=colorPallet, labels = yVal, guide = guide_legend(override.aes = list(label = "foo"))).

like image 92
Brian Avatar answered Sep 09 '25 17:09

Brian