library(reshape2)
library(ggplot2)


#Performs transformations on the columns of the data frame.
#Currently only supports Bool (convert True/False to 0/1)
transformCols <- function(data, col_transforms)
{
  print(col_transforms)
  for (ct in col_transforms)
  {
    col_id = as.numeric(ct[1])
    transform = ct[2]
    if(transform == "Bool")
    {
      data[,col_id] = as.numeric(data[,col_id])
      data[,col_id] = data[,col_id] - 1 #Change 1/2 to 0/1
    }
  }
  return(data)
}

#Adapted from http://www.sthda.com/english/wiki/ggplot2-quick-correlation-matrix-heatmap-r-software-and-data-visualization
plotCorrelations <- function(data, num_col_id)
{
  num_data = data[,c(num_col_id)]
  cormat <- round(cor(num_data),2)
  melted_cormat <- melt(cormat)
  heatplot = ggplot(data = melted_cormat, aes(x=Var1, y=Var2, fill=value)) + 
    geom_tile()
  return(heatplot)
}

plotHists <- function(indata, num_col_id)
{
  for (col_id in num_col_id)
  {
    print(col_id)
    if(class(col_id) == "character") #If string indicies are passed
    {
      print(ggplot(data = indata, aes_string(x = col_id)) + geom_histogram())
    }
    else #If numeric indicies are passed
    {
    print(ggplot(data = indata, aes_(x = as.name(names(indata)[col_id]))) + geom_histogram())
    }
  }
}