```
# scatterplot
# create simulated data, no population mean difference
# X has two values only, Y is numeric
# put into a data frame, required for formula version
n <- 12
f <- sample(c("Group1","Group2"), size=n, replace=TRUE)
x <- round(rnorm(n=n, mean=50, sd=10), 2)
y <- round(rnorm(n=n, mean=50, sd=10), 2)
z <- round(rnorm(n=n, mean=50, sd=10), 2)
mydata <- data.frame(f,x,y,z)
rm(f); rm(x); rm(y); rm(z)
# default scatterplot, x is not sorted so type is set to "p"
# although data not attached, access each variable directly by its name
ScatterPlot(x, y)
# short name
sp(x,y)
# compare to standard R plot, which requires the mydata$ notation
plot(mydata$x, mydata$y)
# save scatterplot to a pdf file
ScatterPlot(x, y, pdf.file="MyScatterScatterPlot.pdf")
# scatterplot, with ellipse and extended axes to accommodate the ellipse
ScatterPlot(x, y, ellipse=TRUE, xlim=c(20,80), ylim=c(20,80))
# scatterplot, with loess line
ScatterPlot(x, y, fit.line="loess")
# increase span (smoothing) from default of .75
ScatterPlot(x, y, fit.line="loess", span=1.25)
# custom scatterplot
ScatterPlot(x, y, col.pts="darkred", col.fill="plum")
# scatterplot with a gray scale color theme
ScatterPlot(x, y, colors="gray")
# by variable scatterplot with default point color, vary shapes
ScatterPlot(x,y, by=f)
# by variable scatterplot with custom colors, keeps only 1 shape
ScatterPlot(x,y, by=f, col.pts=c("hotpink", "steelblue"))
# by variable with characters for plotting symbols
# reduce the size of the plotted symbols with cex<1
ScatterPlot(x, y, by=f, shape.pts=c("F","M"), cex=.6)
# vary both shape and color
ScatterPlot(x, y, by=f, col.pts=c("hotpink", "steelblue"),
shape.pts=c("F","M"))
# by variable dot plot with custom colors, keeps only 1 shape
ScatterPlot(x, by=f, col.pts=c("hotpink", "steelblue"))
# bubble plot of simulated Likert data, 1 to 7 scale
# size of each plotted point (bubble) depends on its joint frequency
# triggered by default when < 10 unique values for each variable
x1 <- sample(1:7, size=100, replace=TRUE)
x2 <- sample(1:7, size=100, replace=TRUE)
ScatterPlot(x1,x2)
# compare to usual scatterplot of Likert data, transparency helps
plot(x1,x2)
ScatterPlot(x1,x2, kind="regular", cex=3, trans.pts=.7)
# plot Likert data and get sunflower plot with loess line
ScatterPlot(x1,x2, kind="sunflower", fit.line="loess")
# scatterplot of continuous Y against categorical X, a factor
Pain <- sample(c("None", "Some", "Much", "Massive"), size=25, replace=TRUE)
Pain <- factor(Pain, levels=c("None", "Some", "Much", "Massive"), ordered=TRUE)
Cost <- round(rnorm(25,1000,100),2)
ScatterPlot(Pain, Cost)
# for this purpose, improved version of standard R stripchart
stripchart(Cost ~ Pain, vertical=TRUE)
# function curve
x <- seq(10,500,by=1)
y <- 18/sqrt(x)
# x is sorted with equal intervals so type set to "l" for line
ScatterPlot(x, y)
# custom function plot
ScatterPlot(x, y, ylab="My Y", xlab="My X", col.line="blue",
col.bg="snow", col.area="lightsteelblue", col.grid="lightsalmon")
# Default dot plot
ScatterPlot(y)
# can also specify DotPlot(y) or dp(y)
DotPlot(y)
# Dot plot with custom colors for outliers
ScatterPlot(y, pt.reg=23, col.out15="hotpink", col.out30="darkred")
# modern art
n <- sample(2:30, size=1)
x <- rnorm(n)
y <- rnorm(n)
clr <- colors()
color1 <- clr[sample(1:length(clr), size=1)]
color2 <- clr[sample(1:length(clr), size=1)]
ScatterPlot(x, y, type="l", lty="dashed", lwd=3, col.area=color1,
col.line=color2, xy.ticks=FALSE, main="Modern Art",
cex.main=2, col.main="lightsteelblue", kind="regular",
n.cat=0)
# -----------------------------------------------
# variables in a different data frame than mydata
# -----------------------------------------------
# variables of interest are in a data frame which is not the default mydata
# although data not attached, access the variable directly by its name
data(datEmployee)
ScatterPlot(Years, Salary, by=Gender, dframe=datEmployee)
```

Run the code above in your browser using DataLab