Skip to content

Commit

Permalink
added coffee data; reverted R/vectors3d to 64bf107
Browse files Browse the repository at this point in the history
  • Loading branch information
friendly committed Oct 22, 2024
1 parent fb84b05 commit 42dce26
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 27 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Consolidate options for `print.latexMatrix`
- Fix bug in `print.latexMatrix(sparse=TRUE)`
- `plotEqn()` gains a `...` to pass other graphical parameters
- added `coffee` data (modified from `spida2`)

# matlib 1.0.0

Expand Down
20 changes: 4 additions & 16 deletions R/vectors3d.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,8 @@
#' rgl.bringtotop()

vectors3d <- function(X, origin=c(0,0,0),
color,
headlength=0.035, ref.length=NULL, radius=1/60,
labels=TRUE,
cex.lab=1.2, adj.lab=0.5, frac.lab=1.1,
draw=TRUE,
col.lab = col,
...) {
headlength=0.035, ref.length=NULL, radius=1/60,
labels=TRUE, cex.lab=1.2, adj.lab=0.5, frac.lab=1.1, draw=TRUE, ...) {

if (is.vector(X)) X <- matrix(X, ncol=3)
n <- nrow(X)
Expand All @@ -71,10 +66,7 @@ vectors3d <- function(X, origin=c(0,0,0),

scale <- c(1, 1, 1)
# radius <- 1/60
ref.length <- arrows3d(OX,
color = color,
headlength=headlength,
scale=scale, radius=radius,
ref.length <- arrows3d(OX, headlength=headlength, scale=scale, radius=radius,
ref.length=ref.length, draw=draw, ...)

if (draw){
Expand All @@ -88,11 +80,7 @@ vectors3d <- function(X, origin=c(0,0,0),
xl = origin[1] + frac.lab * (X[,1]-origin[1])
yl = origin[2] + frac.lab * (X[,2]-origin[2])
zl = origin[3] + frac.lab * (X[,3]-origin[3])
# can't pass color to plotmath3d()
text3d(xl, yl, zl, labels, cex=cex.lab, adj=adj.lab,
# usePlotmath = is.expression(labels),
# color = col.lab,
...)
text3d(xl, yl, zl, labels, cex=cex.lab, adj=adj.lab, ...)
}
}
invisible(c(ref.length=ref.length))
Expand Down
2 changes: 1 addition & 1 deletion dev/test-vectors3d.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ library(matlib)
labs <- c(expression(x[1]), "y", expression(x[2]))
is.expression(labs)

source(here::here("dev", "vectors3d.R"))
#source(here::here("dev", "vectors3d.R"))

open3d()
E <- diag(3)
Expand Down
22 changes: 18 additions & 4 deletions dev/vectors3d.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#'
#' @param X a vector or three-column matrix representing a set of geometric vectors; if a matrix, one vector is drawn for each row
#' @param origin the origin from which they are drawn, a vector of length 3.
#' @param color color for the geometric vectors, recycled as necessary for the rows of \code{X}.
#' @param headlength the \code{headlength} argument passed to \code{\link{arrows3d}} determining the length of arrow heads
#' @param ref.length vector length to be used in scaling arrow heads so that they are all the same size; if \code{NULL}
#' the longest vector is used to scale the arrow heads
Expand All @@ -20,6 +21,7 @@
#' @param adj.lab label position relative to the label point as in \code{\link[rgl]{text3d}}, recycled as necessary.
#' @param frac.lab location of label point, as a fraction of the distance between \code{origin} and \code{X}, recycled as necessary.
#' Values \code{frac.lab > 1} locate the label beyond the end of the vector.
#' @param col.lab color for labels
#' @param draw if \code{TRUE} (the default), draw the vector(s).
#' @param ... other arguments passed on to graphics functions.
#'
Expand Down Expand Up @@ -56,8 +58,13 @@
#' rgl.bringtotop()

vectors3d <- function(X, origin=c(0,0,0),
headlength=0.035, ref.length=NULL, radius=1/60,
labels=TRUE, cex.lab=1.2, adj.lab=0.5, frac.lab=1.1, draw=TRUE, ...) {
color = rep("black", nrow(X)),
headlength=0.035, ref.length=NULL, radius=1/60,
labels=TRUE,
cex.lab=1.2, adj.lab=0.5, frac.lab=1.1,
col.lab = col,
draw=TRUE,
...) {

if (is.vector(X)) X <- matrix(X, ncol=3)
n <- nrow(X)
Expand All @@ -66,7 +73,10 @@ vectors3d <- function(X, origin=c(0,0,0),

scale <- c(1, 1, 1)
# radius <- 1/60
ref.length <- arrows3d(OX, headlength=headlength, scale=scale, radius=radius,
ref.length <- arrows3d(OX,
color = color,
headlength=headlength,
scale=scale, radius=radius,
ref.length=ref.length, draw=draw, ...)

if (draw){
Expand All @@ -80,7 +90,11 @@ vectors3d <- function(X, origin=c(0,0,0),
xl = origin[1] + frac.lab * (X[,1]-origin[1])
yl = origin[2] + frac.lab * (X[,2]-origin[2])
zl = origin[3] + frac.lab * (X[,3]-origin[3])
text3d(xl, yl, zl, labels, cex=cex.lab, adj=adj.lab, ...)
# can't pass color to plotmath3d()
text3d(xl, yl, zl, labels, cex=cex.lab, adj=adj.lab,
# usePlotmath = is.expression(labels),
color = col.lab,
...)
}
}
invisible(c(ref.length=ref.length))
Expand Down
1 change: 0 additions & 1 deletion man/coffee.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ and \code{Stress}, a measure of perceived occupational stress,
in a contrived sample of \eqn{n = 20} university people.
}

}
\usage{data("coffee")}
\format{
A data frame with 20 observations on the following 4 variables.
Expand Down
2 changes: 0 additions & 2 deletions man/vectors3d.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions vignettes/latex-equations.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ title: "LaTeX Equations with latexMatrix, Eqn and matrix2latex"
author: Phil Chalmers, John Fox, Michael Friendly
date: "`r Sys.Date()`"
output:
pdf_document:
toc: true
keep_tex: true
bookdown::html_document2:
base_format: rmarkdown::html_vignette
number_sections: false
Expand All @@ -17,6 +14,12 @@ vignette: >
%\VignetteEngine{knitr::rmarkdown}
---

<!-- Tried to compile to PDF, but this generates errors from TinyTeX
pdf_document:
toc: true
keep_tex: true
-->

```{r nomessages, echo = FALSE}
knitr::opts_chunk$set(
warning = FALSE,
Expand Down

0 comments on commit 42dce26

Please sign in to comment.