R作图之 annotation详解!

您所在的位置:网站首页 r语言locator函数定位错误 R作图之 annotation详解!

R作图之 annotation详解!

2024-03-11 05:17| 来源: 网络整理| 查看: 265

chapter: Annotations 作者:扬眉剑数盟群1:174306879 数盟群2:110875722数盟论坛:http://datameng.com/bbs/forum.php说明:文章内容主要主要来自《R Graphics Cookbook》网盘:http://yun.baidu.com/share/link?shareid=3608279111&uk=1292783730github:https://github.com/gaorongchao/R_Course 最新更改会在github上,其他地方不再修改. 介绍

R Graphics Cookbook 第七章 Annotations 整理而来。

7.1.添加文本注释

用annotate()和text geom(文字对象):如下: annotate 里面用"text"类型,然后x,y分别代表文本的位置。label的内容是文本的实际内容。 annotate 中的类型

text 文本rect 阴影矩形segment 线段 library(ggplot2) # 创建一个图层 p ## > require(datasets) ## ## > require(grDevices); require(graphics) ## ## > ## --- "math annotation" in plots : ## > ## > ###### ## > # create tables of mathematical annotation functionality ## > ###### ## > make.table par(new = TRUE) ## ## > nr nc make.table(nr, nc)

## $mar ## [1] 0 0 0 0 ## ## $pty ## [1] "s" ## ## ## > i draw.plotmath.cell(expression(x + phantom(0) + y), i, nr); i draw.plotmath.cell(expression(x + over(1, phantom(0))), i, nr); i draw.title.cell("Fractions", i, nr); i draw.plotmath.cell(expression(frac(x, y)), i, nr); i draw.plotmath.cell(expression(over(x, y)), i, nr); i draw.plotmath.cell(expression(atop(x, y)), i, nr); i # Need fewer, taller rows and fewer, wider columns for big operators ... ## > nr nc make.table(nr, nc)

## $mar ## [1] 0 0 0 0 ## ## $pty ## [1] "s" ## ## ## > i draw.title.cell("Big Operators", i, nr); i draw.plotmath.cell(expression(sum(x[i], i=1, n)), i, nr); i draw.plotmath.cell(expression(prod(plain(P)(X == x), x)), i, nr); i draw.plotmath.cell(expression(integral(f(x) * dx, a, b)), i, nr); i draw.plotmath.cell(expression(union(A[i], i==1, n)), i, nr); i draw.plotmath.cell(expression(intersect(A[i], i==1, n)), i, nr); i draw.plotmath.cell(expression(lim(f(x), x %->% 0)), i, nr); i draw.plotmath.cell(expression(min(g(x), x >= 0)), i, nr); i draw.plotmath.cell(expression(inf(S)), i, nr); i draw.plotmath.cell(expression(sup(S)), i, nr); i make.table(nr, nc)

## $mar ## [1] 0 0 0 0 ## ## $pty ## [1] "s" ## ## ## > i draw.title.cell("Grouping", i, nr); i draw.plotmath.cell(expression((x + y)*z), i, nr); i draw.plotmath.cell(expression(x^y + z), i, nr); i draw.plotmath.cell(expression(x^(y + z)), i, nr); i # have to do this one by hand ## > draw.plotmath.cell(expression(x^{y + z}), i, nr, string="x^{y + z}"); i draw.plotmath.cell(expression(group("(", list(a, b), "]")), i, nr); i draw.plotmath.cell(expression(bgroup("(", atop(x, y), ")")), i, nr); i draw.plotmath.cell(expression(group(lceil, x, rceil)), i, nr); i draw.plotmath.cell(expression(group(lfloor, x, rfloor)), i, nr); i draw.plotmath.cell(expression(group("|", x, "|")), i, nr); i par(oldpar) ggplot中添加数学公示

ggplot 中的数学表达形式和R基础作图的形式是一样的。

# 正态曲线 p


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3