Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Pass additional arguments to plotmatrix() #158

Closed
jiho opened this Issue Jan 12, 2011 · 2 comments

Comments

Projects
None yet
2 participants
Contributor

jiho commented Jan 12, 2011

Rather than having a just "colour" argument to plotmatrix() add ... and pass it to geom_point, so that any property (not just colour) can be set. E.g.

plotmatrix(d, mapping=aes(colour=someVariable), size=1, alpha=0.7)

Changing the code to this should be enough:

plotmatrix = function (data, mapping = aes(), ...) 
{
    grid <- expand.grid(x = 1:ncol(data), y = 1:ncol(data))
    grid <- subset(grid, x != y)
    all <- do.call("rbind", lapply(1:nrow(grid), function(i) {
        xcol <- grid[i, "x"]
        ycol <- grid[i, "y"]
        data.frame(xvar = names(data)[ycol], yvar = names(data)[xcol], 
            x = data[, xcol], y = data[, ycol], data)
    }))
    all$xvar <- factor(all$xvar, levels = names(data))
    all$yvar <- factor(all$yvar, levels = names(data))
    densities <- do.call("rbind", lapply(1:ncol(data), function(i) {
        data.frame(xvar = names(data)[i], yvar = names(data)[i], 
            x = data[, i])
    }))
    mapping <- defaults(mapping, aes_string(x = "x", y = "y"))
    class(mapping) <- "uneval"
    ggplot(all, mapping) + facet_grid(xvar ~ yvar, scales = "free") + 
        geom_point(na.rm = TRUE, ...) + stat_density(aes(x = x, 
        y = ..scaled.. * diff(range(x)) + min(x)), data = densities, 
        position = "identity", colour = "grey20", geom = "line")
}
Owner

hadley commented Jan 12, 2011

I'm not really willing to change plotmatrix, basically because the whole approach is pretty horrible. Have you looked at ggally?

Contributor

jiho commented Jan 18, 2011

No I didn't. It's great. Add a "deprecated" warning to plotmatrix to point to ggally?

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment