Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to add value numbers on spot in ggplot

my data like this

df<- structure(list(team_3_F = c("browingal ", "newyorkish", "site", 
"team ", "browingal ", "newyorkish", "site", "team ", "browingal ", 
"newyorkish", "site", "team "), variable = structure(c(1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L), .Label = c("AAA_BBB_US", 
"AAA_CCC_US", "AAA_BBB_CCC_US"), class = "factor"), value = c(0.166666666666667, 
0.25, 0, 0.181818181818182, 0.0833333333333333, 1, 0, 0.0909090909090909, 
0.0833333333333333, 0.25, 0, 0.0909090909090909)), row.names = c(NA, 
-12L), class = "data.frame")

I am plotting it like this

ggplot(mydf, aes(x = team_3_F, y = variable)) +
  stat_summary_2d(
    aes(z = value, fill = after_stat(value)),
    geom = "tile"
  )

I want to know if someone who’s how to add the values into the figure (READable?)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

With geom_text:

ggplot(df, aes(x = team_3_F, y = variable)) +
  stat_summary_2d(
    aes(z = value*100, fill = after_stat(value)),
    geom = "tile")+
  geom_text(aes(label=round(value*100,2)))+
  guides(fill=guide_legend(title="Percent"))

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading