R 내장 데이터 Cars93 사용
# 히스토그램
# 1. 데이터 불러오기
aprice <- cars93$Price
# 2. 최소, 최댓값 확인
min(aprice)
max(aprice)
# 히스토그램 + 확률 밀도 그래프 만들기
hist(aprice)
hist( aprice, breaks=seq(0,70,by=1), col="grey",
border="white", prob=T, xlab = 'PRICE', ylim=c(0, 0.1), main='Histogram Of Price')
lines( density(aprice), col="red")
# 산점도
#산점도 그래프 그리기
fig <- plot_ly( data = cars93,
x = ~Price,
y = ~MPG.highway,
type = "scatter",
mode = "markers",
marker = list(color="orange"))
# 추세선
fig <- fig %>% add_trace( x = cars93$Price,
y = fitted( lm(MPG.highway ~ Price, data = cars93)),
type = "scatter",
mode = "lines",
line = list(color = "lightblue"),
name = "Trend Line")
해석 : 차 가격이 높을 수록 고속도로 주행 마일리지가 떨어지는 것을 확인할 수 있다.