[R] ggplot2 help

Glenn Schultz glennmschultz at me.com
Sun Mar 15 20:35:24 CET 2015


All, 

I am doing something wrong but I don't see what.  When I plot in ggplot all the lines are on top of one another but the data is not.  Any help is appreciated.

Thanks,
Glenn 

# -------- I use this function to generate data
Burnout <- function(beta1 = numeric(), 
                      beta2= numeric(), 
                      MaxIncen = numeric(), 
                      LoanAge = numeric()){
  exp(beta1 * LoanAge +  beta2 * MaxIncen)}

# -------------------- Build the data frame for plotting
  BO.Vector <- data.frame(c(seq(1,360,1)))
  BO.Vector[,2] <- cbind(Burnout(beta1 = -.05, beta2 = 0, MaxIncen = 25, LoanAge = BO.Vector[,1]))
  BO.Vector[,3] <- cbind(Burnout(beta1 = -.04, beta2 = 0, MaxIncen = 25, LoanAge = BO.Vector[,1]))
  BO.Vector[,4] <- cbind(Burnout(beta1 = -.03, beta2 = 0, MaxIncen = 25, LoanAge = BO.Vector[,1]))
  BO.Vector[,5] <- cbind(Burnout(beta1 = -.02, beta2 = 0, MaxIncen = 25, LoanAge = BO.Vector[,1]))
  BO.Vector[,6] <- cbind(Burnout(beta1 = -.01, beta2 = 0, MaxIncen = 25, LoanAge = BO.Vector[,1]))

  colnames(BO.Vector) <- c("LoanAge", "-.05", "-.04", "-.03", "-.02", "-.01")
  colnames(BO.vector) <- c("LoanAge", "-.05", "-.04")

# ------------------- reshape 2 prepare for ggplot2
  BO.Vector <- melt(BO.Vector, id = "LoanAge")


# --------------- plot (not working)
  ggplot(BO.Vector, aes(x= LoanAge, y = value, color = variable, linetype = variable)) +
  geom_line()+
  theme_minimal() +
  labs(colour = "Legend", linetype = "Legend", x = "Loan Age", y = "Burnout") + 
  theme(panel.grid.major = element_line(size = .25, color = "grey")) +
  theme(axis.text = element_text(size = 15)) +
  theme(axis.title = element_text(size = 20)) +
  theme(legend.position = c(.9, .4)) +
  scale_colour_manual(values = cbbPalette) 




More information about the R-help mailing list