3D散点图
# create column indicating point color
mtcars$pcolor[mtcars$cyl==4] <- "red"
mtcars$pcolor[mtcars$cyl==6] <- "blue"
mtcars$pcolor[mtcars$cyl==8] <- "darkgreen"
with(mtcars, {
s3d <- scatterplot3d(disp, wt, mpg, # x y and z axis
color=pcolor, pch=19, # circle color indicates no. of cylinders
type="h", lty.hplot=2, # lines to the horizontal plane
scale.y=.75, # scale y axis (reduce by 25%)
main="3-D Scatterplot with mtcars data set",
xlab="Displacement (cu. in.)",
ylab="Weight (lb/1000)",
zlab="Miles/(US) Gallon")
s3d.coords <- s3d$xyz.convert(disp, wt, mpg)
text(s3d.coords$x, s3d.coords$y, # x and y coordinates
labels=row.names(mtcars), # text to plot
pos=4, cex=.5) # shrink text 50% and place to right of points)
# add the legend
legend("topleft", inset=.05, # location and inset
bty="n", cex=.5, # suppress legend box, shrink text 50%
title="Number of Cylinders",
c("4", "6", "8"), fill=c("red", "blue", "darkgreen"))
})
filled.contour(volcano, color = terrain.colors, asp = 1) # simple
x <- 10*1:nrow(volcano)
y <- 10*1:ncol(volcano)
filled.contour(x, y, volcano, color = terrain.colors,
plot.title = title(main = "The Topography of Maunga Whau",
xlab = "Meters North", ylab = "Meters West"),
plot.axes = { axis(1, seq(100, 800, by = 100))
axis(2, seq(100, 600, by = 100)) },
key.title = title(main = "Height\n(meters)"),
key.axes = axis(4, seq(90, 190, by = 10))) # maybe also asp = 1
mtext(paste("filled.contour(.) from", R.version.string),
side = 1, line = 4, adj = 1, cex = .66)
# Annotating a filled contour plot
a <- expand.grid(1:20, 1:20)
b <- matrix(a[,1] + a[,2], 20)
filled.contour(x = 1:20, y = 1:20, z = b,
plot.axes = { axis(1); axis(2); points(10, 10) })
## Persian Rug Art:
x <- y <- seq(-4*pi, 4*pi, len = 27)
r <- sqrt(outer(x^2, y^2, "+"))
filled.contour(cos(r^2)*exp(-r/(2*pi)), axes = FALSE)
## rather, the key *should* be labeled:
filled.contour(cos(r^2)*exp(-r/(2*pi)), frame.plot = FALSE,
plot.axes = {})
联系客服