1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
|
# Scatter Plot ##################################################################
par(mfrow=c(1, 1))
numWeight = mtcars$wt; numWeight
numMpg = mtcars$mpg; numMpg
plot(numWeight, numMpg, main="Scatter Plot for Cars", pch=19,
xlim = c(0, 7), ylim = c(0, 40),
xlab = "Car Weight", ylab = "MPG (Miles Per Gallon)")
# Adding Fit Lines
abline(lm(numMpg ~ numWeight), col="red", lty=1) # Regression by Linear Model
lines(lowess(numWeight, numMpg), col="blue") # lowess line
abline(v=0, col="gray", lty=2)
abline(h=0, col="gray", lty=2)
# Enhanced Scatter Plot
#install.packages("car")
#install.packages("haven")
library(car)
library(haven)
numWeight = mtcars$wt; numWeight
numMpg = mtcars$mpg; numMpg
numCyl = mtcars$cyl; numCyl
dfData = data.frame(numWeight, numMpg, numCyl);
scatterplot(numMpg ~ numWeight | numCyl, data=dfData,
col=c("red", "blue", "darkgreen"),
xlab = "Car Weight", ylab = "MPG (Miles Per Gallon)",
main="Enhanced Scatter Plot", pch=c(18, 19, 20), cex=1.2)
# Scatter Plot Matrix
numWeight = mtcars$wt; numWeight
numMpg = mtcars$mpg; numMpg
numDisp = mtcars$disp; numDisp
dfData = data.frame(numWeight, numMpg, numDisp);
pairs(~ numWeight + numMpg + numDisp, data = dfData)
# Density Scatter Plot
#install.packages("hexbin")
library(hexbin)
numX = rnorm(1000, mean=50, sd=4)
numY = rnorm(1000, mean=100, sd=20)
objBin = hexbin(numX, numY, xbins=50)
plot(objBin, main="Density Scatter Plot")
pdf("C:/Temp/test.pdf")
plot(objBin, main="Density Scatter Plot")
dev.off()
# 3D Scatter Plot
#install.packages("scatterplot3d")
library(scatterplot3d)
numWeight = mtcars$wt; numWeight
numMpg = mtcars$mpg; numMpg
numDisp = mtcars$disp; numDisp
scatterplot3d(numWeight, numMpg, numDisp, main="3D Scatter Plot")
# Spinning 3D Scatter Plot
#install.packages("rgl")
library(rgl)
numWeight = mtcars$wt; numWeight
numMpg = mtcars$mpg; numMpg
numDisp = mtcars$disp; numDisp
plot3d(numWeight, numMpg, numDisp, col="red", size=7)
# Spinning 3D Scatter Plot
install.packages("Rcmdr")
library(Rcmdr)
numWeight = mtcars$wt; numWeight
numMpg = mtcars$mpg; numMpg
numDisp = mtcars$disp; numDisp
scatter3d(numWeight, numDisp, numMpg)
|