1) cex() function

Changing Character Sizes: (The cex Option) The cex (for character expand) function allows to expand or shrink characters within a graph.

plot(c(1,2,3,4,5),c(4,5,3,6,7),
     type="o",
     xlab="sales",
     ylab="advertisement cost",
     main= "Numbers in crores")
text(4,6,"Again there is  a profit",col="blue")

Now, let’s increase the font size.

plot(c(1,2,3,4,5),c(4,5,3,6,7),
     type="o",
     xlab="sales",
     ylab="advertisement cost",
     main= "Numbers in crores")
text(4,6,"Again there is  a profit",col="blue",cex=1.5)

2) The curve() function

Using the curve function, we can a graph between equations.

Que: Plot the function g(t) = (t2 + 1)0.5 for t between 0 and 5.(using curve and plot function)

curve(sqrt(x^2+1),from = 0,to = 5)

3) Adding a Polygon: The polygon() Function

polygon() function is used to draw arbitrary polygonal objects.

f1<-function(t)
    {
    sqrt((t^2)+1)
}

Now, use the polygon function and plota a polygon

x<-seq(from = 0,to = 5)
y<-f1(x)
plot(x,y,type="o")
polygon(c(1.2,1.4,1.4,1.2,4),
        c(0,0,f1(1.3),f1(1.7),1),
        density=10,
        col="red",
        border = "green")

4) Smoothing Points: The lowess() Function

lowess() and loess() functions are used to smoothout the data by fitting it using nonparametric regression.

plot(mtcars$wt,mtcars$hp,type="p")
lines(lowess(mtcars$wt,mtcars$hp),type = "l",col="red")

print(mtcars$wt)
##  [1] 2.620 2.875 2.320 3.215 3.440 3.460 3.570 3.190 3.150 3.440 3.440
## [12] 4.070 3.730 3.780 5.250 5.424 5.345 2.200 1.615 1.835 2.465 3.520
## [23] 3.435 3.840 3.845 1.935 2.140 1.513 3.170 2.770 3.570 2.780
print(mtcars$hp)
##  [1] 110 110  93 110 175 105 245  62  95 123 123 180 180 180 205 215 230
## [18]  66  52  65  97 150 150 245 175  66  91 113 264 175 335 109

5) Saving Graphs

The R graphics display can consist of various graphics devices. The default device is the screen. Inorder to save a graph to a file, you must set up another device.

jpeg(file = "C:/Users/pradeep/OneDrive/R PROGRAMMING/barchart2.jpg")
plot(c(7,12,28,3,41),c(23,32,12,23,34),type="o")
dev.off()
## png 
##   2