I'd like to create a function that will conveniently accept a data frame, then, for each vector in the data frame, plot a histogram. For each additional vector (beyond the first), my function should also print possibly several scatterplots: the additional vector on each other vector in the list of vector arguments.
The result should be a triangular array of plots, ideally faceted.
This is stumping me. So far, I have is the following:
library(ggplot2)
library(reshape2)
scatterHistoChart <- function(data) {
require(ggplot2)
require(reshape2)
#data <- data.frame(...)
data <- melt(data)
graph <- ggplot(data,aes(x=value)) +
geom_histogram() +
# geom_point(aes(x=value)) +
facet_wrap(~variable,scales = "free_x")
return(graph)
}
scatterHistoChart(diamonds)
Edit
Where *
is a histogram, and +
is a scatter plot, the following is an illustration of intended result:
1-vec| *
2-vec| * +
3-vec| * + +
4-vec| * + + +
5-vec| * + + + +
etc. Note that ordering of plots does not matter; the *
's and +
's can be intermixed.