1

I have the following data stored in a dataframe called "astatdf2":

sampletype  variable       value
1  tissue_T1   Entropy 11.61460794
2  tissue_T2   Entropy 14.23313815
3  tissue_T1 Clonality  0.09642700
4  tissue_T2 Clonality  0.03835666
5  tissue_T1      Gini  0.61982789
6  tissue_T2      Gini  0.45175592

I am trying to plot these values with different colors using lines and dots. My only problem is the legend. I tried several solutions, looked in google, in stack etc... but none of them works. How do I get rid off the "a" in the legend and replace it with a circular dot?

library(scales)
library(ggplot2)
p=ggplot(astatdf2, aes(x=sampletype, y=value, group=variable, color=variable))+
    geom_line()+
    geom_point()+
    geom_text(aes(label=round(value, 2)),hjust=0.5, vjust=-1)+
    scale_y_log10(
      breaks = scales::trans_breaks("log10", function(x) 10^x),
      labels = scales::trans_format("log10", scales::math_format(10^.x)),
      limits=c(0.01,50) )+
      labs(color="Estimators")

enter image description here

Edit: I tried the solution here: Remove 'a' from legend when using aesthetics and geom_text putting "geom_text(show.legend = FALSE)" but I get an error.

Fabrizio
  • 927
  • 9
  • 20
  • That was one of the solution I tried. If I add after geom_point() "geom_text( show.legend = FALSE)" I get the following error: Error: geom_text requires the following missing aesthetics: label. – Fabrizio Feb 10 '20 at 09:26
  • 1
    Use `geom_text(aes(label=round(value, 2)),hjust=0.5, vjust=-1, show.legend = FALSE)`. – Ritchie Sacramento Feb 10 '20 at 09:27
  • Yes! I saw a solution here that was quickly deleted. That solution solved my problem. Please put it back such that I can accept it. – Fabrizio Feb 10 '20 at 09:29
  • Any solution on this? – pRo May 16 '23 at 20:31

1 Answers1

1

You can remove the text legend by setting show.legend = FALSE inside geom_text.

geom_text(aes(label=round(value, 2)),hjust=0.5, vjust=-1, show.legend = FALSE)
penguin
  • 1,267
  • 14
  • 27
  • Please don't post only code as an answer, but include an explanation what your code does and how it solves the problem of the question. Answers with an explanation are generally of higher quality, and are more likely to attract upvotes. – Mark Rotteveel Feb 10 '20 at 10:59
  • Thought it was self explanatory. Added comments. – penguin Feb 10 '20 at 11:03