Friday, April 5, 2013

RG #4: basic XY plot with regression line (with diffrent plotting parameters) in R

# data
length <- c(10.2, 35, 16.3, 8.9, 14.2, 20.1, 4.3)
width <- c(3.2, 1.5, 2.3, 4.9, 16.2, 3.1, 5.3)


# simple scatter plot
plot(length, width)

# adding regression line
 abline(lm(width ~ length))
# add title
title("Regression of length on width")



# with different parameters, see ?par to see what they mean
  plot(length, width, type ="b" , lty = 2, main = " main title", sub = " sub title", xlab = " x variable (units) ", ylab = " y variable units ", bg = "white", bty= "7", cex= 2, cex.axis = 1,
cex.lab = 1, cex.main = 2, cex.sub = 1, col = "red", col.axis = "black", col.lab = "black",
col.main = "blue", col.sub = "black", family = "sans", fg = "black", font = 3, font.axis = 3,
font.main = 2, font.sub =1, pch = 19, tck = 1 )




# adding grid lines
 grid(nx = 40, ny = 40, col = "lightgray", lty = "dotted", lwd = par("lwd"), equilogs = TRUE)


# adding regression line
abline(lm(width ~ length))

# changing box:
box(lty = '1373', col = 'blue')



 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.