데카르트방식 : plot(x,y)

수식기반 : plot(y~x)

plot()

plot(y축 data, option)

plot( c(1,2,3,4,5))

option main = " [ main title ] "
sub = " [ sub title ] "
xlab = " [x axis text ] “, ylab =” [ y axis text ] "
ann = F – x, y 축 no title tmag = 2 – 문자 확대율 axes = F – hide x,y axis axis – show x,y axis - ## Graph Type Selection type = “p” – 점 , default type = “l” – 선 type = “b” – 점과 선 type = “c” – b 에서 점 생략 type = “o” – 점과 선을 중첩 type = “h” – 점에서 x축까지 수직선 그래프 type = “s” – 왼쪽값을 기초로 계단모양으로 연결한 그래프 type = “n” – 축 만 그리고 그래프는 없음 ## Line Type lty = 0, lty = “blank” – 투명선 lty = 1, lty = “solid” – 실선 lty = 2, lty = “dashed” – 대쉬선 lty = 3, lty = “dotted” – 점선 lty = 4, lty = “dotdash” – 점선과 대쉬선 lty = 5, lty = “longdash” – 긴 대쉬선 lty = 6, lty = “twodash” – 2개의 대쉬선 ## Color, Symbol col = 1, col = “blue” – 기호 색지정 1. black 2. red 3. green 4. blue 5. sky 6. purple 7. yellow 8. gray pch = 0, pch = “[character]” – 점의 모양 bg = “blue” – 그래프 배경색 lwd = “[number]” – 선의 굵기 cex = “[number]” – 점이나 문자의 굵기

연속형 데이터 그래프

산점도

geom_point()
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.5.1
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.5.1
library(rvest)
## Warning: package 'rvest' was built under R version 3.5.1
## Loading required package: xml2
## Warning: package 'xml2' was built under R version 3.5.1
library(RColorBrewer)
library(data.table)
## Warning: package 'data.table' was built under R version 3.5.1
## 
## Attaching package: 'data.table'
## The following objects are masked from 'package:dplyr':
## 
##     between, first, last
library(reshape)
## Warning: package 'reshape' was built under R version 3.5.1
## 
## Attaching package: 'reshape'
## The following object is masked from 'package:data.table':
## 
##     melt
## The following object is masked from 'package:dplyr':
## 
##     rename
library(stringr)
## Warning: package 'stringr' was built under R version 3.5.1
set.seed(1228)
var.rand <- data.frame(
  obs <- 1 : 20,
  val <- sample(
    1 : 10,
    size = 20,
    replace = T
  )
)
ggplot(
  data = var.rand,
  aes(
    x = obs,
    y = val
  )
)+geom_point()

점 확대

ggplot(
  data = var.rand
)+geom_point(
  aes(
    x = obs,
    y = val
  ),
  color = "blue",  # 포인트 색깔& 사이즈 추가
  size = 5
)

선으로 연결

set.seed(3000)
var.rand <- data.frame(
  obs <- 1 : 20,
  val <- sample(
    1 : 10,
    size = 20,
    replace = T
  )
)
ggplot(
  data = var.rand
)+geom_line(
   aes(
    x = obs,
    y = val
  )
)

선 두께&색상 조절

ggplot(
  data = var.rand
)+geom_line(
   aes(
    x = obs,
    y = val
  ),
  color = "red",  # 선 색깔& 사이즈 추가
  size = 5
)

#### 선 과 포인트 혼합

set.seed(123)

dfRand <- data.frame(aa = 1:10,
  bb = sample(1:10, 10)
)
head(dfRand)
ggplot(data = dfRand,
  aes(x = aa,
    y = bb
  )
)+geom_point(size = 5)+
  geom_line(size = 1.5)+
  geom_point(size = 3, color = "#FFFFFF")

선과 바차트 혼합

dfDemo1 <- data.frame(aa=1:10, bb=10:1)
dfDemo2 <- data.frame(cc=1:10, dd=1:10)
ggplot(
  data = dfDemo2,
  aes(x=cc, y=dd)
)+ geom_col(data=dfDemo1,
            aes(x=aa,y=bb))+
  geom_point(size=5)+
  geom_line(size=1.5)+
  geom_point(size=3,
             color="#FFFFFF")

#### 과일예제

target <- c(100,130,120,160,150)
plot(
  target,
  type = 'o',
  col = 'red',
  ylim = c(0,200),
  axes = F,
  ann = F
)
axis(
  1,
  at = 1:5,
  lab = c('월','화','수','목','금')
)
axis(
  2,
  ylim = c(0,200)
)
title(
  main = "과일",
  col.main = "red",
  font.main = 4
)
title(
  xlab = "요일",
  col.lab = "black"
)
title(
  ylab = "가격",
  col.lab = "blue"
)