Skip to content

Commit

Permalink
example using substitute with mathematical expressions
Browse files Browse the repository at this point in the history
somewhat lengthy but effective idiom for plotting mathematical
expressions with values taken from variables in the R session
  • Loading branch information
kevinushey committed Apr 12, 2013
1 parent 24a771a commit 2a72ff0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ cache/
_source/figure/
_source/cache/
_source/__*
.Rproj.user
*.Rproj
7 changes: 7 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ authors:
github: kbroman
twitter: kwbroman
bio: Department of Biostatistics and Medical Informatics, University of Wisconsin-Madison; research in statistical genetics; developer of R/qtl (for R)
kushey:
name: Kevin Ushey
email: [email protected]
homepage: http://cdrv.github.io
github: cdrv
twitter: kevin_ushey
bio: MSc., University of British Columbia; interested in statistical genetics and data visualization

# The production_url is only used when full-domain names are needed
# such as sitemap.txt
Expand Down
22 changes: 21 additions & 1 deletion _source/2013-04-08-mathematical-annotation-in-r.Rmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: post
title: "Mathematical Annotation in R"
author: [rcore, yulijia, kbroman]
author: [rcore, yulijia, kbroman, kushey]
categories: [Base Graphics]
tags: [mathematical annotation, Greek letters]
reviewer: [yihui]
Expand Down Expand Up @@ -33,3 +33,23 @@ plot(rnorm(100), rnorm(100),
xlab = expression(hat(mu)[0]), ylab = expression(alpha^beta),
main = expression(paste("Plot of ", alpha^beta, " versus ", hat(mu)[0])))
```

Finally, if we want to include variables from an R session in mathematical
expressions, and substitute in their actual values, we can use `substitute`.

```{r math-text-sub, fig.width=5, fig.height=4, tidy=FALSE}
par( mar=c(4, 4, 2, 0.1) )
x_mean <- 1.5
x_sd <- 1.2
hist( rnorm(100, x_mean, x_sd),
main=as.expression( substitute(
expr=paste(
"Histogram of 100 samples from X ~ N(", x_mean, ", ", x_sd^2, ")"
),
env=list(
x_mean=x_mean,
x_sd=x_sd
)
) )
)
```

0 comments on commit 2a72ff0

Please sign in to comment.