在ggplot2的单个面上注释文本

在ggplot2的单个面上注释文本

本文介绍了在ggplot2的单个面上注释文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  library(ggplot2)$ b我想用以下代码在剧情的最后一个面上注释一些文字:

(bp),(b),(b),(b)和(b)中的至少一个。 label =Test,size = 4,x = 15,y = 5)
print(p)


但是这个代码在每个方面都注释了文本。如果您指导我如何仅在一个方面获得注释文本,我将非常感激。

解决方案

通常您会这样做:

  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)

它应该没有完全指定因子变量,但可能会引发一些警告:
$ b


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 <- p + facet_grid(. ~ cyl)
p <- p + annotate("text", label = "Test", size = 4, x = 15, y = 5)
print(p)

But this code annotates the text on every facet. I would highly appreciate if you guide me how to get the annotated text on only one facet. Thanks in advance.

解决方案

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:

这篇关于在ggplot2的单个面上注释文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 23:59