graph_func <- function(){
graphics.off()
data <- readline('그래프를 그릴 테이블을 입력하세요 : ')
data <- get(data)
tot_set <- colnames(data)
tot_col <- menu(tot_set, title = '합산할 컬럼을 선택하세요.')
tot_col <- tot_set[tot_col]
group_set <- colnames(data)
group_col <- menu(group_set, title = '그룹핑 할 컬럼을 선택하세요.')
group_col <- group_set[group_col]
graph_set <- c('막대그래프', '원형그래프')
graph_type <- menu(graph_set, title = '그래프 종류를 선택하세요.')
plot_data <- tapply(data[,tot_col], data[,group_col], sum)
switch(graph_type,
barplot = {
barplot(plot_data,
main = paste('Total ',
toupper(tot_col),
'Bar Chart',
'Grouped By',
toupper(group_col)),
ylab = tot_col,
cex.names = .8,
ylim = c(0, max( plot_data )*1.3),
col = rainbow(nrow(plot_data)))
},
piechart = {
label <- paste(rownames(plot_data),
round(plot_data/sum(plot_data)*100, 1), '%')
pie(plot_data,
main = paste('Total ',
toupper(tot_col),
'Pie Chart',
'Grouped By',
toupper(group_col)),
col = rainbow(nrow(plot_data)),
labels = label)
}
)
}