Sei sulla pagina 1di 1

line graphs:

str(cars)

plot(cars, main="Cars Dataset")

type description
------ --------------
p points
l lines
o overplotted points and lines
b, c points (empty if "c") joined by lines
s, S stair steps
h histogram-like vertical lines
n does not produce any points or lines

plot(cars, main="Cars Dataset", type="o", xlab="Car speed : mph",


ylab="Distance covered to stop car : ft")

x <- c(1,2,3,4,5,6,7,8)
y <- c(1,3,8,11,14,17,19,22)

plot(x,y)
lmout <- lm(y ~ x)
lmout
abline(lmout)

In R, the lm(), or linear model, function can be used to create a simple


regression model. The lm() function accepts a number of arguments (Fitting Linear
Models,)

In y ~ x :
x is known as predictor variable.(independent)
y is known as response variable.(dependent on x)

lmout : displays simple information of linear regression model.


summary(lmout) : displays detailed information of linear regression model.

plot(y,x,col = "blue",main = "linear model",


abline(lm(x~y)), cex = 1.3, pch = 16,
xlab="x value",
ylab="y value")

Text and Symbol Size


The following options can be used to control text and symbol size in graphs.

option description
cex number indicating the amount by which plotting text and symbols
should be scaled relative to the default.
1=default, 1.5 is 50% larger, 0.5 is 50% smaller, etc.
cex.axis magnification of axis annotation relative to cex
cex.lab magnification of x and y labels relative to cex
cex.main magnification of titles relative to cex
cex.sub magnification of subtitles relative to cex

Potrebbero piacerti anche