R 데이터 분석
[SKK_DA1] plotting mtcars in R 단순 시각화 연습
YONG_X
2017. 5. 20. 00:50
data(mtcars)
head(mtcars)
# colors()[405:409] # 색상 고르기
# colors()[381:400]
plot(mtcars$wt, mtcars$mpg, pch=19,
col=colors()[ifelse(mtcars$hp>median(mtcars$hp), 402 , 385)],
cex=mtcars$hp/100,
main="연비와 무게간 관계 :: mtcars(원크기는 마력)" ,
xlab="무게", ylab="연비"
)
# color()[385 ] == "khaki3"
# color()[385 ] == "lightblue3"
abline(lm( mtcars$mpg~mtcars$wt), lty=2, col="darkgrey")
lines(lowess(mtcars$mpg~mtcars$wt), col="orange", lty=3) # 폴리노미얼 커브 추가
text(mtcars$wt, mtcars$mpg, labels=row.names(mtcars), cex=0.5, pos=3)
text(median(mtcars$wt)*1.5, median(mtcars$mpg)*1.4, labels="무게3.5, 연비15 근처가 \n 최악의 집단 ", cex=0.7) # 주석(설명) 추가
grid(col="darkgrey") # 기본색상을 변경한 참조선 그리드
#====================