2024-06-21

R에서 ggplot 사용해서 그래프 그리기 (Plot with ggplot in R)

Install the ggplot2 package in Rstudio.

(Rstudio에서 ggplot2 패키지를 설치합니다.)




Click the "Install" button here.
(Install 버튼을 누르면 설치가 됩니다.)

Load the ggplot2 package in Rstudio Console.
(콘솔에서 ggplot2 패키지를 loading합니다.)



Make a simple data frame df with only 2 columns named x and y.
(데이터프레임 df를 만듭니다. 두 개의 컬럼으로 된 간단한 데이터프레임 입니다.)


Let's use ggplot!
(이제 ggplot을 사용해봅니다.)

Nothing happened. Because we've just regitered df to be used, but it's not used yet.
(아무것도 그려지지 않네요. 이제부터 df를 사용해서 뭘 좀 하겠다고 등록만 해 준 상태입니다.)


  Using aes(), add the information of which columns in df will be the x- and y-axes.
(df에서 어떤 컬럼을 사용할지 aes()를 이용해서 정보를 추가해줍니다.)


We've just registered the columns, so the axes and ranges are shown but still nothing appears.
(x축에 df의 x컬럼을 사용하고 y축에 df의 y컬럼을 사용하겠다고 등록만 된 상태입니다. 그래서 축과 범위는 데이타에 맞춰서 이미 만들어져있네요.)

Add the first geometric ogject. geom_point() addes points.
(ggplot의 geom(geometric object)를 추가해줍니다. geom_point()는 점을 추가하겠다는 뜻입니다.)


Yay, it's the first plot with ggplot!
(ggplot을 이용한 첫번째 plot이 그려졌네요!!)

For the line, use geom_line().
(선을 추가 하고 싶다면, geom_line()을 추가해주세요.)


In this way, you can add geometric objects.
(이런 식으로 원하는 geometric object를 추가해주면 됩니다.)

This is it. It's the basic way ggplot works!
여기까지가, ggplot의 기본 사용 방법입니다!