<코드>
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
--------------------------------------------------
내용 :
부주의에 의한 화재 유형 중 어떤 유형에 의해 가장 많은 화재가 발생하는 지 그래프를 만들려고 했는데
이런 오류가 떠서 질문 드립니다 ..ㅠㅠㅠㅠ 뭐가 문제일까요? ㅠㅠㅠㅠ
No. | Subject | Author | Date |
---|---|---|---|
1254 | moonbook package mycsv 관련 오류 문의드립니다. [2] | qwetyui | 2023.11.30 |
1253 | logistic regression 명령어 문의드립니다. [2] | 로렌쵸메디치 | 2023.11.22 |
1252 | spss 파일 불러오기. [1] | 통계린 | 2023.11.22 |
1251 | PSM 매칭변수 숫자 관련 문의입니다. [1] | 오하나 | 2023.11.22 |
1250 | Multiple imputation 관련 질문 및, age adjusted incidence rate 관련 질문을 드립니다. | YSKBH | 2023.11.15 |
1249 | semMediation 설치 재문의드립니다 [3] | 마술샘 | 2023.11.11 |
1248 | 안녕하세요. 정회원 문의 [1] | lionking | 2023.11.06 |
1247 | PSM 관련 질문드립니다. | dr. | 2023.11.05 |
1246 | ggplot [1] | 통계린 | 2023.10.30 |
1245 | 정회원 [1] | 통계린 | 2023.10.29 |
1244 | PSM 관련 질문 드립니다. [2] | 로렌쵸메디치 | 2023.10.25 |
1243 | forest plot 그림이 전체가 다 나오지 않습니다. [1] | joyguni | 2023.10.08 |
1242 | PSM caliper default 값 관련 문의드립니다. [1] | Ooppps | 2023.10.05 |
1241 | reliability test tool,,, [1] | FAdavid | 2023.10.05 |
1240 | 정회원 가입 확인 요청드립니다. [1] | osman | 2023.10.03 |
1239 | 생존분석, cox 회귀 관련 기초적인 질문 입니다. | 만니톨 | 2023.09.27 |
1238 | Twang-mnps에서 매칭된 데이터를 추출하는 방법 좀 알려주세요 | Dorocy | 2023.09.26 |
1237 | 영수증 발급을 부탁드립니다. [1] | 규빈어멈 | 2023.09.26 |
1236 | 정회원 확인 [2] | lionking | 2023.09.24 |
1235 | autoReg 에러 문의드립니다 [1] | 소소 | 2023.09.23 |
ds의 컬럼명을 잘못 지정해주신 것 같습니다.
마지막 라인만
ggplot(ds, aes(x=pop_cause.cause, y=pop_num, fill=pop_cause.cause)) + geom_bar(stat = "identity") +
theme(axis.text.x=element_text(angle=45,colour="blue", size=10))