Annotating text on individual facet in ggplot2

前端 未结 6 827
野的像风
野的像风 2020-11-22 09:39

I want to annotate some text on last facet of the plot with the following code:

library(ggplot2)
p <- ggplot(mtcars, aes(mpg, wt)) + geom_point()
p <-          


        
6条回答
  •  抹茶落季
    2020-11-22 10:16

    Typically you'd do something like this:

    ann_text <- data.frame(mpg = 15,wt = 5,lab = "Text",
                           cyl = factor(8,levels = c("4","6","8")))
    p + geom_text(data = ann_text,label = "Text")
    

    It should work without specifying the factor variable completely, but will probably throw some warnings:

    enter image description here

提交回复
热议问题