~ubuntu-branches/ubuntu/hardy/texmacs/hardy

« back to all changes in this revision

Viewing changes to plugins/r/r/TeXmacs/demo/T.graphics.R

  • Committer: Bazaar Package Importer
  • Author(s): Ralf Treinen
  • Date: 2004-04-19 20:34:00 UTC
  • Revision ID: james.westby@ubuntu.com-20040419203400-g4e34ih0315wcn8v
Tags: upstream-1.0.3-R2
ImportĀ upstreamĀ versionĀ 1.0.3-R2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
if(dev.cur() <= 1) get(getOption("device"))()
 
2
 
 
3
#opar <- par(ask = interactive() &&
 
4
#            (.Device %in% c("X11", "GTK", "gnome", "windows", "Macintosh")))
 
5
# For source
 
6
 
 
7
## Here is some code which illustrates some of the differences between
 
8
## R and S graphics capabilities.  Note that colors are generally specified
 
9
## by a character string name (taken from the X11 rgb.txt file) and that line
 
10
## textures are given similarly.         The parameter "bg" sets the background
 
11
## parameter for the plot and there is also an "fg" parameter which sets
 
12
## the foreground color.
 
13
 
 
14
 
 
15
x <- rnorm(50)
 
16
opar <- c(par(bg="white"))
 
17
plot(x, ann=FALSE, type="n")
 
18
abline(h=0, col=gray(.90))
 
19
lines(x, col="green4", lty="dotted")
 
20
points(x, bg="limegreen", pch=21)
 
21
title(main="Simple Use of Color In a Plot",
 
22
      xlab="Just a Whisper of a Label",
 
23
      col.main="blue", col.lab=gray(.8),
 
24
      cex.main=1.2, cex.lab=1.0, font.main=4, font.lab=3)
 
25
v()
 
26
 
 
27
## A little color wheel.         This code just plots equally spaced hues in
 
28
## a pie chart. If you have a cheap SVGA monitor (like me) you will
 
29
## probably find that numerically equispaced does not mean visually
 
30
## equispaced.  On my display at home, these colors tend to cluster at
 
31
## the RGB primaries.  On the other hand on the SGI Indy at work the
 
32
## effect is near perfect.
 
33
 
 
34
par(bg="gray")
 
35
pie(rep(1,24), col=rainbow(24), radius=0.9)
 
36
title(main="A Sample Color Wheel", cex.main=1.4, font.main=3)
 
37
title(xlab="(Use this as a test of monitor linearity)", cex.lab=0.8, font.lab=3)
 
38
v()
 
39
 
 
40
 
 
41
## We have already confessed to having these.  This is just showing off X11
 
42
## color names (and the example (from the postscript manual) is pretty "cute".
 
43
 
 
44
pie.sales <- c(0.12, 0.3, 0.26, 0.16, 0.04, 0.12)
 
45
names(pie.sales) <- c("Blueberry", "Cherry",
 
46
                      "Apple", "Boston Cream", "Other", "Vanilla Cream")
 
47
pie(pie.sales,
 
48
    col=c("purple","violetred1","green3","cornsilk","cyan","white"))
 
49
title(main="January Pie Sales", cex.main=1.8, font.main=1)
 
50
title(xlab="(Don't try this at home kids)", cex.lab=0.8, font.lab=3)
 
51
 
 
52
v()
 
53
 
 
54
## Boxplots:  I couldn't resist the capability for filling the "box".
 
55
## The use of color seems like a useful addition, it focuses attention
 
56
## on the central bulk of the data.
 
57
 
 
58
par(bg="cornsilk")
 
59
n <- 10
 
60
g <- gl(n, 100, n*100)
 
61
x <- rnorm(n*100) + sqrt(codes(g))
 
62
boxplot(split(x,g), col="lavender", notch=TRUE)
 
63
title(main="Notched Boxplots", xlab="Group", font.main=4, font.lab=1)
 
64
v()
 
65
 
 
66
 
 
67
## An example showing how to fill between curves.
 
68
 
 
69
par(bg="white")
 
70
n <- 100
 
71
x <- c(0,cumsum(rnorm(n)))
 
72
y <- c(0,cumsum(rnorm(n)))
 
73
xx <- c(0:n, n:0)
 
74
yy <- c(x, rev(y))
 
75
plot(xx, yy, type="n", xlab="Time", ylab="Distance")
 
76
polygon(xx, yy, col="gray")
 
77
title("Distance Between Brownian Motions")
 
78
v()
 
79
 
 
80
 
 
81
## Colored plot margins, axis labels and titles.         You do need to be
 
82
## careful with these kinds of effects. It's easy to go completely
 
83
## over the top and you can end up with your lunch all over the keyboard.
 
84
## On the other hand, my market research clients love it.
 
85
 
 
86
x <- c(0.00, 0.40, 0.86, 0.85, 0.69, 0.48, 0.54, 1.09, 1.11, 1.73, 2.05, 2.02)
 
87
par(bg="lightgray")
 
88
plot(x, type="n", axes=FALSE, ann=FALSE)
 
89
usr <- par("usr")
 
90
rect(usr[1], usr[3], usr[2], usr[4], col="cornsilk", border="black")
 
91
lines(x, col="blue")
 
92
points(x, pch=21, bg="lightcyan", cex=1.25)
 
93
axis(2, col.axis="blue", las=1)
 
94
axis(1, at=1:12, lab=month.abb, col.axis="blue")
 
95
box()
 
96
title(main="The Level of Interest in R", font.main=4, col.main="red")
 
97
title(xlab="1996", col.lab="red")
 
98
v()
 
99
 
 
100
 
 
101
## A filled histogram, showing how to change the font used for the
 
102
## main title without changing the other annotation.
 
103
 
 
104
par(bg="cornsilk")
 
105
x <- rnorm(1000)
 
106
hist(x, xlim=range(-4, 4, x), col="lavender", main="")
 
107
title(main="1000 Normal Random Variates", font.main=3)
 
108
v()
 
109
 
 
110
 
 
111
## A scatterplot matrix
 
112
## The good old Iris data (yet again)
 
113
 
 
114
data("iris")
 
115
pairs(iris[1:4], main="Edgar Anderson's Iris Data", font.main=4, pch=19)
 
116
v(width=6,height=6)
 
117
pairs(iris[1:4], main="Edgar Anderson's Iris Data", pch=21,
 
118
      bg=c("red", "green3", "blue")[codes(iris$Species)])
 
119
v(width=6,height=6)
 
120
 
 
121
 
 
122
## Contour plotting
 
123
## This produces a topographic map of one of Auckland's many volcanic "peaks".
 
124
 
 
125
data("volcano")
 
126
x <- 10*1:nrow(volcano)
 
127
y <- 10*1:ncol(volcano)
 
128
l <- pretty(range(volcano), 10)
 
129
par(bg="lightcyan")
 
130
pin <- par("pin")
 
131
xdelta <- diff(range(x))
 
132
ydelta <- diff(range(y))
 
133
xscale <- pin[1]/xdelta
 
134
yscale <- pin[2]/ydelta
 
135
scale <- if(xscale < yscale) xscale else yscale
 
136
xadd <- 0.5*(pin[1]/scale-xdelta)
 
137
yadd <- 0.5*(pin[2]/scale-ydelta)
 
138
plot(numeric(0), numeric(0),
 
139
     xlim=range(x)+c(-1,1)*xadd, ylim=range(y)+c(-1,1)*yadd,
 
140
     type="n", ann=FALSE)
 
141
usr <- par("usr")
 
142
rect(usr[1], usr[3], usr[2], usr[4], col="green3")
 
143
contour(x, y, volcano, levels=l, col="yellow", lty="solid", add=TRUE)
 
144
box()
 
145
title("A Topographic Map of Maunga Whau",font=4)
 
146
title(xlab="Meters North", ylab="Meters West", font=3)
 
147
mtext("10 Meter Contour Spacing", side=3, line=0.35, outer=FALSE,
 
148
      at=mean(par("usr")[1:2]), cex=0.7, font=3)
 
149
v()
 
150
 
 
151
## Conditioning plots
 
152
 
 
153
par(bg="cornsilk")
 
154
data(quakes)
 
155
coplot(lat ~ long | depth, data=quakes, pch=21, bg="green3")
 
156
v()
 
157
 
 
158
#par(opar)