peach <- c(10, 5, 20, 5, 20, 30, 20)
banana <- c(5, 10, 20, 15, 10, 20, 5)
orange <- c(10, 5, 30, 35, 10, 30, 10)
fruit <- data.frame( peach, banana, orange)

# bar차트를 그룹으로 묶어 출력할때는 반드시 출력 대상이 Matrix 여야 함
barplot(as.matrix(fruit),main="일별 과일 판매량", col=rainbow(nrow(fruit)))

barplot(as.matrix(fruit),main="일별 과일 판매량", beside=T, col=rainbow(nrow(fruit)), ylim=c(0, 50))
legend("topright", legend= c("월","화","수","목","금","토","일"), cex=0.8, fill=rainbow(nrow(fruit)))

# 조건에 맞는 그래프 출력 : peach 활용

drawBarplot <-function()
{
  peach <- c(10, 5, 20, 5, 20, 30, 20)
  colors <-c() 
  for(i in  1:length(peach))
    {
    if(peach[i]>=30)
      {
      colors <-c(colors, "red")
      }
    else if (peach[i] >=20)
      {
      colors <-c(colors, "green")
      }
    else
      {
      colors <-c(colors, "yellow")
      }
}
  barplot(peach, main="일별 배 판매량", col=colors, ylim=c(0, 50), names.arg=c("월","화","수","목","금","토","일"))
}
drawBarplot( )