setwd(c:\\data)
food <- read.csv("food_info.csv", header = T, fileEncoding = 'euc-kr')
# 데이터 확인
head(food)
# 가로 출력
icecream <- food [ grep("^아이스크림", food$식품명), c("식품명")]
icecream_counts <- table(icecream)
icecream_counts <- length(icecream_counts)
nut <- food [ grep("^견과류", food$식품명), c("식품명")]
nut_counts <- table(nut)
nut_counts <- length(nut_counts)
bread <- food [ grep("빵", food$식품명), c("식품명")]
bread_counts <- table(bread)
bread_counts<- length(bread_counts)
# DF
categories <- c("ice cream", "nut", "bread")
counts <- c(icecream_counts, nut_counts, bread_counts)
# 색깔 지정
colors <- c("gold", "skyblue", "tomato")
# plotly 사용해 막대 그래프 생성
fig <- plot_ly ( x = categories,
y = as.numeric(counts),
type = 'bar',
marker = list(color = colors))
# 데이터 출력
fig