# scatter plot
x <- rnorm(25)
y <- rnorm(25)
# default scatterplot, x is not sorted so type is set to "p"
color.plot(x, y)
# compare to standard R plot
plot(x, y)
# scatterplot, with ellipse and extended axes to accomodate the ellipse
color.plot(x, y, ellipse=TRUE, xlim=c(-3,3), ylim=c(-3,3))
# scatterplot, with lowess line added
color.plot(x, y, fit.line="lowess")
# custom scatter plot
color.plot(x, y, col.point="darkred", col.fill="plum")
# scatterplot of Likert data, 1 to 7 scale, and get bubble plot
# 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)
color.plot(x1,x2)
# compare to usual scatterplot of Likert data
color.plot(x1,x2, kind="regular")
# plot Likert data and get sunflower plot with lowess line
color.plot(x1,x2, kind="sunflower.freq", fit.line="lowess")
# 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)
color.plot(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
color.plot(x, y)
# custom function plot
color.plot(x, y, ylab="My Y", xlab="My X", col.line="blue",
col.bg="snow", col.area="lightsteelblue", col.grid="lightsalmon")
# generate data randomly varying about a constant mean
y <- rnorm(25)
# default run chart
color.plot(y)
# compare to standard R plot
plot(y, type="l")
# customize run chart, pch=24: filled triangle point-up,
color.plot(y, lwd=2, col.point="sienna3", pch=24,
col.bg="mintcream", ylim=c(-3.5,3.5), center.line="median")
# generate steadily increasing values
y <- sort(rexp(50))
# default line chart
color.plot(y)
# line chart with border around plotted values
color.plot(y, col.area="transparent")
# time series chart, i.e., with dates, and filled area
# with option label for the x-axis
color.plot(y, time.start="2005/09/01", time.by="month")
# 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)]
color.plot(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")
Run the code above in your browser using DataLab