Skip to content

plotEqn() - can't supply labels for lines #68

@friendly

Description

@friendly

In dev/plotEqn-test.R, I've tried to supply my own labels for lines, b/c I want to use x and y for the variables and simplify the equations to the form y = a + b * x. I have a test version in dev/plotEqn.R, where I'd like to also add options to control the solution points, allowing the argument solution = list(pch =, cex=, col=)

(This is for an example where I'd like to show the duality of points and lines in data / beta space.)

A <- matrix(c( 1, 2, 0,
               -1, 2, 1), 3, 2) |> print()

b <- c(2, 1, 1)
# works OK
plotEqn(A, b, vars = c("x", "y"))
        
# try to change the labels: doesn't work
plotEqn(A, b, vars = c("x", "y"),
        labels = c("y = x - 2",
                   "y = 1/2 - x",
                   "y = 1"))

The lines appear, but not the labels

image

I can't see what is wrong with the relevant code in the function (around line 132)

    if (!is.null(labels)) {
      xl <- if(A[i, 2] == 0) b[i] else x[1]
      label <- parse(text=sub("=", "==", labels[i]))
      text(xl, y[1], label, col=col[i], pos=4)
    }

Related to this is the fact that the simplify argument doesn't simplify as much as I'd like:

> showEqn(A, b, vars = c("x", "y"), simplify = TRUE)
  x - 1*y  =  2 
2*x + 2*y  =  1 
0*x   + y  =  1 

It would be nicer if this gave (aligned)

  x -       y  =  2 
2*x + 2*y  =  1 
             y  =  1 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions