Skip to menu

<코드>

 

pop <- read.csv('부주의에+의한+화재발생(소방서별)_20221214144839.csv', header=FALSE, encoding="UTF-8")

pop_header <- pop[1:2,]

pop_header

pop_data <- pop[3:nrow(pop),]

colnames(pop_data) <- c('Firestation1','Firestation2','category','cause','num')

head(pop_data)

 

idx <- which(pop_data[,'Firestation2']=='소계')

pop_cause <- pop_data[idx,]

 

pop_cause <- pop_cause[1:nrow(pop_cause),]

head(pop_cause)

ds <- data.frame(pop_num = as.numeric(pop_data$num),

                pop_cause$cause)

ds

colnames(ds)

 

library(ggplot2)

ggplot(ds,aes(x= pop_cause, y=pop_num, fill=colnames(ds))) +

  geom_bar(stat = "identity") +

  theme(axis.text.x=element_text(angle=45,colour="blue", size=10))

 

------------------------------------------------

 

<오류>
Don't know how to automatically pick scale for object of
type <data.frame>. Defaulting to continuous.
Error in `geom_bar()`:
! Problem while computing aesthetics.
ℹ Error occurred in the 1st layer.
Caused by error in `check_aesthetics()`:
! Aesthetics must be either length 1 or the same
  as the data (220)
✖ Fix the following mappings: `x` and `fill`
Run `rlang::last_error()` to see where the error occurred.
 
-------------------------------------------------
 
데이터 : https://data.seoul.go.kr/dataList/10949/S/2/datasetView.do
 
--------------------------------------------------
 
내용 : 
부주의에 의한 화재 유형 중 어떤 유형에 의해 가장 많은 화재가 발생하는 지 그래프를 만들려고 했는데
이런 오류가 떠서 질문 드립니다 ..ㅠㅠㅠㅠ 뭐가 문제일까요? ㅠㅠㅠㅠ