金魚亭日常

読書,ガジェット,競技プログラミング

ggplot2, annotate(), italic, sprintf()

library(dplyr)
library(ggplot2)

r <- 0.80
lb <- paste0('\'', sprintf("%.2f", r), '\'')
iris %>% ggplot(aes(x = Petal.Width, y = Petal.Length, group=Species, colour = Species)) + 
  geom_point() + 
  annotate('text', label=paste(expression(italic("r")~"="), lb, sep = "~"), x=2, y=2, parse=TRUE)

f:id:what_alnk:20170926162740p:plain