r - How to add axis labels to a simple.scatterplot (UsingR) -
the package usingr
has great out of box plotting tools. however, using simple.scatterplot
function can't figure out how add axis labels.
library(usingr) simple.scatterplot(iris$sepal.length, iris$sepal.width, xlab='hello axis') error in plot.default(x, y, xlim = xrange, ylim = yrange, xlab = "x", : formal argument "xlab" matched multiple actual arguments
the graph can of course produced without using xlab arg, , tried using mtext
command, label ends in middle of page.
mtext(side=1, text='hello axis')
i tried editing function without success either:
mysimple.scatterplot <- function (x, y) { def.par <- par(no.readonly = true) n <- length(x) xhist <- hist(x, sqrt(n), plot = false) yhist <- hist(y, sqrt(n), plot = false) top <- max(c(xhist$counts, yhist$counts)) xrange <- c(min(x), max(x)) yrange <- c(min(y), max(y)) nf <- layout(matrix(c(2, 0, 1, 3), 2, 2, true), c(3, 1), c(1, 3), true) layout.show(nf) par(mar = c(3, 3, 1, 1)) plot(x, y, xlim = xrange, ylim = yrange, xlab = 'hello x-axis', ylab = 'hello y-axis', ...) abline(lm(y ~ x)) par(mar = c(0, 3, 1, 1)) barplot(xhist$counts, axes = false, ylim = c(0, top), space = 0, col = gray(0.95)) par(mar = c(3, 0, 1, 1)) barplot(yhist$counts, axes = false, xlim = c(0, top), space = 0, col = gray(0.95), horiz = true) par(def.par) }
the cause here:
layout.show(nf) par(mar = c(3, 3, 1, 1)) # <-- here plot(x, y, xlim = xrange, ylim = yrange, xlab = 'hello x-axis', ylab = 'hello y-axis', ...)
the margins changed small value labels not in plot, outside of area.
Comments
Post a Comment