pi_notation | R Documentation |
\pi
notationThis function re-expresses a vector of numbers in terms of \pi
, returning an expression
object that can be added to a plot.
pi_notation(x, as_fraction = TRUE, as_bar = TRUE, ...)
x |
A numeric vector. |
as_fraction |
A logical value that defines whether or not to express sequential multipliers of |
as_bar |
If |
... |
Additional arguments passed to |
The function is designed to be used on a regular sequence of numbers (e.g., representing the tick marks on a plot) within pretty_plot
.
The function returns an expression
object.
Edward Lavender
pretty_axis
(and subsidiary plotting functions, such as pretty_plot
) can implement this function internally.
#### Example (1): Implement the function in isolation
x <- seq(0, 8, by = 0.25*pi)/pi
pi_notation(x)
pi_notation(x, as_bar = FALSE)
pi_notation(x, as_fraction = FALSE)
#### Example (2): Plotting with fractions
## Stacked fraction
xlabels <- pi_notation(x, as_fraction = TRUE)
plot(x, rep(0, length(x)), axes = FALSE)
axis(side = 1, at = x*pi, labels = xlabels, col = "red")
## Spread fraction
x_axis <- pi_notation(x, as_fraction = TRUE, as_bar = FALSE)
plot(x, rep(0, length(x)), axes = FALSE)
axis(side = 1, at = x*pi, labels = xlabels, col = "red")
#### Example (3): Plotting with decimals
x_axis <- pi_notation(1:3, as_fraction = FALSE)
plot(x, rep(0, length(x)), axes = FALSE)
axis(side = 1, at = x*pi, labels = xlabels, col = "red")
#### Example (4): pi_notation() is implemented automatically in prettyGraphics
# ... via pretty_axis(), pretty_plot() etc.
## Define example time series of lunar phase in radians
dat <- data.frame(date = seq.Date(as.Date("2016-01-01"), as.Date("2016-02-01"), by = 1))
dat$lunar <- lunar::lunar.phase(dat$date)
## Visualise lunar phase time series, with pi_notation
pretty_plot(dat$date, dat$lunar,
pretty_axis_args = list(pi_notation = list(NULL, list()))
)
add_moons(side = 2, pos = min(dat$date), radius = 0.5)
## Customise pi_notation
# Use as_bar = FALSE
pretty_plot(dat$date, dat$lunar,
pretty_axis_args = list(pi_notation = list(NULL, list(as_bar = FALSE)))
)
add_moons(side = 2, pos = min(dat$date), radius = 0.5)
# Use decimals
pretty_plot(dat$date, dat$lunar,
pretty_axis_args = list(pi_notation = list(NULL, list(as_fraction = FALSE)))
)
add_moons(side = 2, pos = min(dat$date), radius = 0.5)
## Use pi_notation within specified axis limits
pretty_plot(dat$date, dat$lunar,
ylim = c(0, 2*pi),
pretty_axis_args = list(pi_notation = list(NULL, list()))
)
add_moons(side = 2, pos = min(dat$date), radius = 0.5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.