# install libraries
# This demo requires the 'ggplot' package
if( !is.element("ggplot2", installed.packages()[,1]) )
install.packages("ggplot2")
# load libraries
library(ggplot2)
download.file("http://www.openintro.org/stat/data/evals.RData", destfile = "evals.RData")
load("evals.RData")
# this function will create a histogram of every variable in your data frame
# the function takes one argument ('data') which is the name of your data frame
# if you want to save the scatter plots as .png files define the file path for graphs_folder below
# you will also need to remove the "#" from the two lines in the function that are commented out and place a "#" before print
# save graphs in this folder
graphs_folder <- '/filepath/graphs/'
hist <- function(x, na.rm = TRUE, ...) {
nm <- names(x)
for (i in seq_along(nm)) {
print(ggplot(x,aes_string(x = nm[i])) + geom_histogram(alpha=.8, fill = "darkblue") + theme_classic()) }
#plots <- ggplot(x,aes_string(x = nm[i])) + geom_histogram(alpha=.8, fill = "darkblue") + theme_classic()
#ggsave(plots,filename=paste(graphs_folder, "hist_",nm[i],".png",sep=""))}
}
hist(evals)
den <- function(x, na.rm = TRUE, ...) {
x <- x[,sapply(x,is.numeric) | sapply(x,is.integer)]
nm <- names(x)
for (i in seq_along(nm)) {
print(ggplot(x,aes_string(x = nm[i])) + geom_density(alpha=.8, fill = "darkgreen") + theme_classic())}
}
den(evals)