산점도는 가로 및 세로 축에 개별 데이터 조각을 나타내는 점 집합입니다. 두 변수의 값을 X축과 Y축으로 표시한 그래프에서 결과 점의 패턴은 두 변수 사이의 상관 관계를 나타냅니다.
R – 분산형 차트
우리는 만들 수 있습니다 ㅏ 산점도 R 프로그래밍 언어 사용하여 구성() 기능.
통사론: 플롯(x, y, 메인, xlab, ylab, xlim, ylim, 축)
매개변수:
x: 이 매개변수는 수평 좌표를 설정합니다. y: 이 매개변수는 수직 좌표를 설정합니다. xlab: 이 매개변수는 가로축의 레이블입니다. ylab: 이 매개변수는 세로축의 레이블입니다. main: 이 매개변수 main은 차트의 제목입니다. xlim: 이 매개변수는 x 값을 그리는 데 사용됩니다. ylim: 이 매개변수는 y 값을 그리는 데 사용됩니다. 축: 이 매개변수는 플롯에 두 축을 모두 그려야 하는지 여부를 나타냅니다.
단순 산점도 차트
산점도 차트를 생성하려면:
- 우리는 mtcars 데이터 세트를 사용합니다.
- mtcars에서 wt 및 mpg 열을 사용합니다.
예:
아르 자형
input <- mtcars[,> c> (> 'wt'> ,> 'mpg'> )]> print> (> head> (input))> |
>
>
산출:
산점도 그래프 만들기
R 산점도 그래프를 생성하려면:
- 그래프를 그리는 데 필요한 매개변수를 사용하고 있습니다.
- 이 'xlab'은 X축을 설명하고 'ylab'은 Y축을 설명합니다.
예:
아르 자형
# Get the input values.> input <- mtcars[,> c> (> 'wt'> ,> 'mpg'> )]> # Plot the chart for cars with> # weight between 1.5 to 4 and> # mileage between 10 and 25.> plot> (x = input$wt, y = input$mpg,> > xlab => 'Weight'> ,> > ylab => 'Milage'> ,> > xlim => c> (1.5, 4),> > ylim => c> (10, 25),> > main => 'Weight vs Milage'> )> |
>
>
산출:

R 언어의 산점도
산점도 행렬
두 개 이상의 변수가 있고 한 변수와 다른 변수 사이의 상관 관계를 원할 때 R 산점도 행렬을 사용합니다.
한 쌍() 함수는 산점도의 행렬을 생성하는 데 사용됩니다.
통사론: 쌍(수식, 데이터)
매개변수:
공식: 이 매개변수는 쌍으로 사용되는 일련의 변수를 나타냅니다. data: 이 매개변수는 변수를 가져올 데이터 세트를 나타냅니다.
예:
아르 자형
보토3
# Plot the matrices between> # 4 variables giving 12 plots.> # One variable with 3 others> # and total 4 variables.> pairs> (~wt + mpg + disp + cyl, data = mtcars,> > main => 'Scatterplot Matrix'> )> |
>
>
산출:

R 언어의 산점도
적합치가 표시된 산점도
R 산점도 차트를 생성하려면:
- 우리는 산점도를 생성하기 위해 ggplot() 및 geom_point() 함수를 제공하는 ggplot2 패키지를 사용하고 있습니다.
- 또한 우리는 mtcars에서 wt 및 mpg 열을 사용하고 있습니다.
예:
아르 자형
# Loading ggplot2 package> library> (ggplot2)> > # Creating scatterplot with fitted values.> # An additional function stst_smooth> # is used for linear regression.> ggplot> (mtcars,> aes> (x => log> (mpg), y => log> (drat))) +> > geom_point> (> aes> (color => factor> (gear))) +> > stat_smooth> (method => 'lm'> ,> > col => '#C42126'> , se => FALSE> , size = 1> )> |
>
>
산출:

R 언어의 산점도
동적 이름으로 제목 추가
R 산점도 차트를 생성하려면 부제목을 추가하세요.
- 우리는 추가 함수를 사용합니다. ggplot에서는 'aes', 'geom_point'를 추가하여 mtcars 데이터 세트를 추가합니다.
- 제목, 캡션, 부제목을 사용하세요.
예:
아르 자형
# Loading ggplot2 package> library> (ggplot2)> > # Creating scatterplot with fitted values.> # An additional function stst_smooth> # is used for linear regression.> new_graph<-> ggplot> (mtcars,> aes> (x => log> (mpg),> > y => log> (drat))) +> > geom_point> (> aes> (color => factor> (gear))) +> > stat_smooth> (method => 'lm'> ,> > col => '#C42126'> ,> > se => FALSE> , size = 1)> # in above example lm is used for linear regression> # and se stands for standard error.> # Adding title with dynamic name> new_graph +> labs> (> > title => 'Relation between Mile per hours and drat'> ,> > subtitle => 'Relationship break down by gear class'> ,> > caption => 'Authors own computation'> )> |
>
>
산출:

R 언어의 산점도
3D 산점도
여기서는 R 산점도3D 패키지를 사용하여 3D 산점도를 생성합니다. 이 패키지는 산점도3d() 메서드를 사용하여 R 산점도를 3D로 그릴 수 있습니다.
아르 자형
# 3D Scatterplot> library> (plotly)> attach> (mtcars)> plot_ly> (data=mtcars,x=~mpg,y=~hp,z=~cyl,color=~gear)> |
>
>
산출:

R 언어의 산점도