Dimitry Kovalev
Dimitry Kovalev

Reputation: 13

stat_summary_2d with geom="text"

I need to plot a heatmap of mean values. It is pretty straightforward.

ggplot(data, aes(x=var1, y=var2, z=var3)+
stat_summary_2d(fun=“mean“,geom="tile")

I need a text above the tiles representing same values.

I tried,

 +stat_summary_2d(fun="mean", geom="text")

but it requires label aesthetic and I don't know what to write there.

Upvotes: 1

Views: 892

Answers (1)

mt1022
mt1022

Reputation: 17299

You can access the computed variable at each cell with ..value... As you didn't provide data, below is an example using diamonds dataset:

library(ggplot2)

ggplot(diamonds, aes(carat, depth, z = price)) +
    stat_summary_2d(fun = 'mean') +
    stat_summary_2d(aes(label = ..value..), fun="mean", geom="text") 

Upvotes: 1

Related Questions