|
The quantlets
grmove
and
grrot
allow the user to move graphic primitives
without losing information including lines or line styles.
grrot
knows 4
counterclockwise rotations: 0 no rotation, 1 rotation by 90 degree, 2
rotation by 180 degree and 3 rotation by 270 degree. Since the rotation
center is always (0,0), you should rotate first and then move the graphic
primitive.
library("plot") ; loads library plot data = read ("bostonh") ; reads Boston Housing data gro1 = grbox (data[,11]) ; boxplot of 11th variable gro2 = grbox (data[,13]) ; boxplot of 13th variable gro3 = grbox (data[,14]) ; boxplot of 14th variable gro1 = grrot (gro1, 1) ; rotates first boxplot gro2 = grrot (gro2, 1) ; rotates second boxplot gro2 = grmove (gro2, #(1.5,0)) ; moves second boxplot 1.5 right gro3 = grrot (gro3, 1) ; rotates the third boxplot gro3 = grmove (gro3, #(3,0)) ; moves third boxplot 3.0 right plot(gro1, gro2, gro3) ; shows the boxplots
We see that all three variables, pupil-teacher ratio (PTRATIO), percentage lower status people (LSTAT) and median house prices (MEDV), are skewed, especially the last one (median house prices).
For the convenience of the user, some simple graphic primitives are
predefined:
grxline
which draws a line from
to
,
gryline
which draws a line from
to
, and
grcircle
which draws a circle.
Let's draw a two-dimensional standard normal distributed data set. Furthermore, we
include the coordinate system axes as well as the circle which contains of
the data of a bivariate standard normal distribution.
library("graphic") ; loads library graphic randomize(0) ; initializes random generator x = normal(200,2) ; generates 200 bivariate data xl = grxline(0, x[,1]) ; computes horizontal axis yl = gryline(0, x[,2]) ; computes vertical axis cl = grcircle(2.44775) ; computes circle with radius 2.44775 d = createdisplay(1,1) ; creates display show(d,1,1,x,xl,yl,cl) ; draws everything in one plot
If we count the number of observations outside the circle we will
find nine. Since we have generated points we would
expect around ten (
) observations outside the circle.
XploRe has eight standard colors ( 0 - black, 1 - blue, 2 - green, 3 - cyan, 4 - red, 5 - magenta, 6 - yellow and 7 - white ) which sit in the corners of the RGB cube. We support RGB colors with Red, Green and Blue ranging from 0 to 255. The number of available colors depends on your monitor and windows system.
However, the RGB system is not well suited to construct a path through the
color space, e.g. for contour lines indicating maxima by red lines and
minima by blue lines. The HLS color model is much better suited for that.
Thus we provide the quantlets
rgb2hls
and
hls2rgb
to transform a specific
color from a color model into another.
Note that if we want to use colors other than the standard ones then
it's necessary to create the colors by
createcolor
, since
your output device supports
-bit colors, but is not
able to display them all simultaneously. Thus, we support a color
palette of 256 colors (minus the 8 standard colors).
library("plot") ; loads the library plot h = grid (120,26.6666,4) ; creates grid in HLS double cone l = 0.5.*matrix(rows(h)) s = matrix(rows(h)) rgb = hls2rgb(h~l~s) ; transfers HLS model to RGB model x0 = #(-3, -3) h = #(0.2, 0.2) n = #(31, 31) x = grid(x0, h, n) ; generates a bivariate grid f = exp(-(x[,1]^2+x[,2]^2)/1.5)/(1.5*pi) ; computes density of bivariate ; normal with correlation 0.5 c = 0.2*(1:4).*max(f) ; contour lines as 10%,...,90% ; times the maximum density createcolor(rgb) ; generates the necessary colors gr = grcontour2(x~f, c, rgb) ; generates surface plot(gr) ; plots the surface
![]() |
Note that the object rgb is really a matrix. The
first vector represents the value for red, the second the value
for blue and the last the value for green.