R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

R 마크다운 작업 직접 해보기: 연습문제

아래의 예시처럼 문서가 나올 수 있게 마크다운을 사용해 보세요.

문서 이름, 저자는 다르게 나타내도 상관없으며 날짜는 실습일을 기준으로 합니다.

install.packages(“ggplot2”) install.packages(“dplyr”)

친환경 자동차 브랜드 마케팅 팀 보고서

보고일자: 2025년 6월 9일 (월요일)
보고 장소: 수원특례시
보고 담당 직원: 마케팅 팀2부 000


보고사항 1. 연비 분포 파악하기

자동차의 cty(도시 연비) 변수가 전체적으로 어떻게 분포되어 있는지 히스토그램을 통해 시각화합니다.
drv(구동 방식)에 따라 색을 달리하여 그룹을 구분했습니다.

조건:
- binwidth = 2
- fill = drv
- position = "identity"
- alpha = 0.5

library(ggplot2)
library(dplyr)

mpg$drv <- as.factor(mpg$drv)

ggplot(mpg, aes(x = cty, fill = drv)) +
  geom_histogram(position = "identity", binwidth = 2, alpha = 0.5)

해석:
- 도시 연비가 15~20 사이에 많이 분포하며, 후륜 구동이 평균적으로 연비가 낮은 경향을 보임


보고사항 2. 자동차 등급(class)별 연비 비교

자동차의 등급(class)에 따라 도시 연비(cty)에 차이가 있는지 상자 그림(Boxplot)을 통해 비교합니다.

ggplot(mpg, aes(x = class, y = cty)) +
  geom_boxplot()

해석:
- pickup, suv는 연비가 낮고, compact, subcompact는 연비가 높은 편이다.


보고사항 3. 구동방식(drv), 변속기(trans)별 고속도로 연비 비교

변속기별(trans)로 그룹을 나누고 구동 방식(drv)을 색상으로 구분하여 고속도로 연비(hwy) 분포를 확인합니다.

ggplot(mpg, aes(x = hwy, fill = drv)) +
  geom_histogram(binwidth = 2, alpha = 0.5) +
  facet_wrap(~trans)

해석:
- manual보다 auto에서 연비 분포가 넓게 나타나고,
4륜 구동 차량은 전체적으로 연비가 낮은 편이다.


보고서 마무리

이상 보고를 마칩니다. 감사합니다.