'Add standard deviation text overlay on ggplot geom_point()

A plot:

library(tidyverse)
diamonds |> 
  filter(x > 0) |> 
  ggplot(aes(x = x, y = log(price))) +
  geom_point()

Looks like this: enter image description here

The standard deviation of log(diamonds$Price) (filtered where x > 0) is 1.014611:

diamonds |> 
  filter(x > 0) |> 
  pull(price) |> 
  log() |> 
  sd() # 1.014611

I wouldlike to overlay this on top of my plot somewhere and call it just 'sd'. In this case it would say 'sd = 1.014611'. Can I do this?

[EDIT]

Bonus if across facets. Tried:

annotations <- diamonds |> 
  filter(x > 0) |> 
  group_by(cut) |> 
  summarise(sd_log_price = paste0("sd = ", round(sd(log(price)), 2)))

diamonds |> 
  filter(x > 0) |> 
  ggplot(aes(x = x, y = log(price))) +
  geom_point() +
  geom_text(label = annotations$sd_log_price) + # Error: Aesthetics must be either length 1 or the same as the data (53932): label
  facet_wrap(. ~ cut)

But this throws the error in the comment.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source