cars <- read.csv("C:\\data\\usedcars.csv")
unique(cars$model) # "SEL" "SE" "SES"
sel = cars[cars$model == 'SEL', c("model", "price")]
se = cars[cars$model == 'SE', c("model", "price")]
ses = cars[cars$model == 'SES', c("model", "price")]
# 바이올린 플롯 그리기
data = rbind(sel, se, ses)
library(ggplot2)
ggplot(data, aes(x=model, y=price, fill=model)) +
geom_violin(trim=FALSE) +
geom_boxplot(width =0.2, fill='white') +
labs(title='Violin Plot of Used Car Price', x="model", y="Price") +
theme_minimal()
해석
- 폭이 넓을 수록 해당 데이터의 빈도가 많은 것 - 데이터가 좁은 범위에 집중된 경우 좁고 긴 형태 / 데이터가 넓게 퍼져 있는 경우 넓고 짧은 형태
1. 모델 SEL - 중앙값이 가장 높음 - 범위 12.5K-17.5K 내에 가격이 집중되어 있음 - 데이터 건수는 23개로 가장 적음. => 대부분이 비슷하게 비싼 가격에 판매됨. 셋 중 가장 최신형 모델
mean(cars[cars$model=='SEL' ,'mileage']) # 26238.91 mean(cars[cars$model=='SEL' ,'year']) # 2010.087 => 전체 데이터의 평균 year가 2008.7, 전체 데이터의 평균 mileage가 약 44K인 것을 고려하면 전체적으로 최근에 생산되었고 mileage가 낮음. 히스토그램에서 명확히 확인됨.
2. 모델 SES - 이상치가 없고 한 구간에 가격이 집중되기 보다는 다양한 가격에 판매 - 데이터 건수가 가장 많은 모델로 연식이 다양한 차량의 섞여 있을 수 있겠음.
3. 모델 SE - 중앙값이 가장 낮고 하한보다 낮은 가격에 판매된 건수가 4번 있었음.
--------------------------------------------------------------------------------- **SEL 이상치
cars[cars$model=='SEL' & (cars$price <13584 | cars$price > 19995), ]
year model price mileage color transmission 1 2011 SEL 21992 7413 Yellow AUTO 2 2011 SEL 20995 10926 Gray AUTO => mileage가 낮아서 높은 가격에 판매 114 2009 SEL 10995 78264 Gray AUTO => mileage가 높아서 낮은 가격에 판매
------------------------------------------------------------------------------------------- **SE 이상치 cars[cars$model=='SE' & (cars$price <6980 | cars$price > 17500), ]
year model price mileage color transmission 147 2002 SE 5995 87003 Red AUTO 148 2000 SE 5980 96841 Red AUTO 149 2001 SE 4899 151479 Yellow AUTO 150 2000 SE 3800 109259 Red AUTO
=> 2000-2002년으로 생산된지 오래되었고 mileage가 80-15K로 아주 높아 싸게 판매 |