Home > database >  how to add value numbers on spot in ggplot
how to add value numbers on spot in ggplot

Time:03-15

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?)

CodePudding user response:

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

  • Related