I am trying to get some basic bar graphs for a few variables. While running few codes, I am getting the output graphs as desired. But for some, the output is not proper and the graphs are mono-color(gray). Unable to figure out what error it is. I have attached the output for the 2nd graph. Kindly let me know where I am going wrong. I am pretty new to R programming.
The data set MD loooks like this
State Year Desc Amt
TN 2014 Won 158
OK 2015 Lost 175
WA 2013 Won 145
OG 2015 Lost 174
IL 2014 Won 165
library(ggplot2)
#Metric for AB */
AB <- ddply(MD,c("State","Year", "Desc"),
function (MD){data.frame( Total_Lo=nrow(MD), Total_Amt=sum(MD$Lo_Amt), Avg_Amt=mean(MD$Lo_Amt))})
#Loan Amount metric for States
A <-ddply(AB,c("State", "Desc"),
function(AB){data.frame(Number_A=sum(AB$Total_Lo),Total_Amt_A=sum(AB$Total_Amt), Avg_Amt_A=sum(AB$Total_Amt)/sum(AB$Total_Lo))})
#Loan Amount Metric for Years
B <-ddply(AB,c("Year" , "Desc"),
function(AB){data.frame(Number_B=sum(AB$Total_Lo),Total_B=sum(AB$Total_Amt),Avg_B=sum(AB$Total_Amt)/sum(AB$Total_Lo))})
#Getting proper output
qplot(State, data = A,
fill=State, geom = "bar",
weight=Total_Amt_,ylab="Total Amount",
main = "Total Amount for all ")
#Getting output but no color
qplot(Year, data = B, fill=_Year,
geom = "bar",weight=Number_B,ylab="Total Count ",
main = " Number by Year")
#No proper output
qplot(State, data = AB, fill=Year,
geom = "bar",weight=Total_Number_Lo,
ylab="Total Number", main = "Number each state ")