2.3 Membuat Grafik Fungsi Dua Variabel

Tambahkan Library mosaicCalc terlebih dahulu.

library(mosaicCalc)
## Warning: package 'mosaicCalc' was built under R version 4.2.2
## Loading required package: mosaic
## Warning: package 'mosaic' was built under R version 4.2.2
## Registered S3 method overwritten by 'mosaic':
##   method                           from   
##   fortify.SpatialPolygonsDataFrame ggplot2
## 
## The 'mosaic' package masks several functions from core packages in order to add 
## additional features.  The original behavior of these functions should not be affected by this.
## 
## Attaching package: 'mosaic'
## The following objects are masked from 'package:dplyr':
## 
##     count, do, tally
## The following object is masked from 'package:Matrix':
## 
##     mean
## The following object is masked from 'package:ggplot2':
## 
##     stat
## The following objects are masked from 'package:stats':
## 
##     binom.test, cor, cor.test, cov, fivenum, IQR, median, prop.test,
##     quantile, sd, t.test, var
## The following objects are masked from 'package:base':
## 
##     max, mean, min, prod, range, sample, sum
## Loading required package: mosaicCore
## Warning: package 'mosaicCore' was built under R version 4.2.2
## 
## Attaching package: 'mosaicCore'
## The following objects are masked from 'package:dplyr':
## 
##     count, tally
## 
## Attaching package: 'mosaicCalc'
## The following object is masked from 'package:stats':
## 
##     D

Anda telah melihat bagaimana memplot grafik fungsi dari satu variabel, misalnya:

slice_plot(
  95 - 73*exp(-.2*t) ~ t, 
  domain(t = 0:20) )

pelajarannya adalah tentang memplot fungsi dua variabel. Sebagian besar, format yang digunakan adalah plot kontur.

Anda menggunakan contour_plot() untuk memplot dengan dua variabel masukan. Anda perlu mencantumkan dua variabel di sebelah kanan tanda +, dan Anda perlu memberikan rentang untuk masing-masing variabel. Sebagai contoh:

contour_plot(
  sin(2*pi*t/10)*exp(-.2*x) ~ t & x, 
  domain(t = range(0,20), x = range(0,10)))

Kadang-kadang, orang ingin melihat fungsi sebagai permukaan, diplot dalam 3 dimensi. Anda bisa membuat komputer menampilkan plot perspektif 3 dimensi dengan menggunakan fungsi interactive_plot() . Seperti yang akan Anda lihat dengan mengarahkan mouse di sekitar plot, ini interaktif.

interactive_plot(
   sin(2*pi*t/10)*exp(-.5*x) ~ t & x, 
   domain(t = 0:20, x = 0:10))