Title: | Graphical User Interface (GUI) for Interactive R Analysis Sessions |
---|---|
Description: | Really Poor Man's Graphical User Interface, used to create interactive R analysis sessions with simple R commands. |
Authors: | Jonathan M. Lees [aut, cre], Jake Anderson [ctb] |
Maintainer: | Jonathan M. Lees <[email protected]> |
License: | GPL (>= 2) |
Version: | 2.2-7 |
Built: | 2025-02-14 02:39:01 UTC |
Source: | https://github.com/cran/RPMG |
Really Poor Man's Graphical User Interface, used to create interactive R analysis sessions with simple R commands.
Jonathan M. Lees <[email protected]>
rowBUTTONS, whichbutt
### get sample image data set. data(volcano) ##### set sample interval unit attr(volcano, 'dx') =10 attr(volcano, 'dy') =10 ### create the list of labels ### Actions for these buttons are described in the calling program XSECDEM mybutts = c("DONE", "REFRESH", "rainbow", "topo", "terrain", "CONT", "XSEC","PS" ) XSECDEM(volcano, mybutts) ############################################# ############################################# CODE STUB ## Not run: ### Example code chunk: ### general set up of RPGM usage: ###### make a plot ####### set buttons buttons = rowBUTTONS(c("BUT1","BUT2") , col=c(1,1), pch=c(1,1)) ####### after plotting, locate in plot.... zloc = locator() Nclick = length(zloc$x) ############# the last click on the screen before stopping (middle ############# mouse click) is used to set the action K = whichbutt(zloc , buttons) while(TRUE) { if(K[Nclick] == match("BUT1", labs, nomatch = NOLAB)) { ### do what ever button 1 is supposed to do } if(K[Nclick] == match("BUT2", labs, nomatch = NOLAB)) { ### do what ever button 2 is supposed to do } } ## end while loop ## End(Not run)
### get sample image data set. data(volcano) ##### set sample interval unit attr(volcano, 'dx') =10 attr(volcano, 'dy') =10 ### create the list of labels ### Actions for these buttons are described in the calling program XSECDEM mybutts = c("DONE", "REFRESH", "rainbow", "topo", "terrain", "CONT", "XSEC","PS" ) XSECDEM(volcano, mybutts) ############################################# ############################################# CODE STUB ## Not run: ### Example code chunk: ### general set up of RPGM usage: ###### make a plot ####### set buttons buttons = rowBUTTONS(c("BUT1","BUT2") , col=c(1,1), pch=c(1,1)) ####### after plotting, locate in plot.... zloc = locator() Nclick = length(zloc$x) ############# the last click on the screen before stopping (middle ############# mouse click) is used to set the action K = whichbutt(zloc , buttons) while(TRUE) { if(K[Nclick] == match("BUT1", labs, nomatch = NOLAB)) { ### do what ever button 1 is supposed to do } if(K[Nclick] == match("BUT2", labs, nomatch = NOLAB)) { ### do what ever button 2 is supposed to do } } ## end while loop ## End(Not run)
Example of how to use RPMG button functions. This example shows how to plot a DEM and interactively change the plot and find projected cross-sections through a surface.
aGETXprofile(jx, jy, jz, LAB = "A", myloc = NULL, PLOT = FALSE, asp=1)
aGETXprofile(jx, jy, jz, LAB = "A", myloc = NULL, PLOT = FALSE, asp=1)
jx , jy
|
locations of grid lines at which the values in 'jz' are measured. |
jz |
a matrix containing the values to be plotted |
LAB |
Alphanumeric (A-Z) for labeling a cross section |
myloc |
Out put of Locator function |
PLOT |
logical. Plot is created if TRUE |
asp |
aspect ration, see par |
The program uses a similar input format as image or contour, with structure from the locator() function of x and y coordinates that determine where the cross section is to be extracted.
Returns a list of x,z values representing the projected values along the cross section.
RX |
distance along cross section |
RZ |
values extracted from the elevation map |
The program is an auxiliary program provided to illustrate the RPMG interactive R analysis.
Jonathan M. Lees<[email protected]>
locator, image
## Not run: ####### get data data(volcano) #### extract dimensions of image nx = dim(volcano)[1] ny = dim(volcano)[2] ### establish units of image jx = 10*seq(from=0, to=nx-1) jy = 10*seq(from=0, to=ny-1) #### set a letter for the cross section LAB = LETTERS[1] ### coordinates of cross section on image ### this is normally set by using the locator() function x1 = 76.47351 y1 = 231.89055 x2 = 739.99746 y2 = 464.08185 ## extract and plot cross section aGETXprofile(jx, jy, volcano, myloc=list(x=c(x1, x2), y=c(y1, y2)), LAB=LAB, PLOT=TRUE) ## End(Not run)
## Not run: ####### get data data(volcano) #### extract dimensions of image nx = dim(volcano)[1] ny = dim(volcano)[2] ### establish units of image jx = 10*seq(from=0, to=nx-1) jy = 10*seq(from=0, to=ny-1) #### set a letter for the cross section LAB = LETTERS[1] ### coordinates of cross section on image ### this is normally set by using the locator() function x1 = 76.47351 y1 = 231.89055 x2 = 739.99746 y2 = 464.08185 ## extract and plot cross section aGETXprofile(jx, jy, volcano, myloc=list(x=c(x1, x2), y=c(y1, y2)), LAB=LAB, PLOT=TRUE) ## End(Not run)
Break a vector into segments
breakline.index(Z, ww)
breakline.index(Z, ww)
Z |
vector |
ww |
indices where the breaks should occur. if a matrix is provided the start and end indices are given, else the breaks are provded. |
Codes used for maps to break map segments along boundaries. But this is more general, nd can be used to break any vector according to given indices. See examples.
List of indices that are segments.
Jonathan M. Lees<[email protected]>
### example with a vector of breaks h = 1:20 k = breakline.index(h, c(8, 14)) ######## select with a matrix of start-ends r1 = rbind(c(3,10), c(14, 18)) k = breakline.index(h, r1) j1 = seq(from=3, to=17, by=3) j2 = j1+5 ########## overlapping sequences r1 = cbind(j1, j2) k = breakline.index(h, r1) ###### example with coordinates #### some data: uu=list() uu$x=c(136.66,136.34,136.07,136.07,135.62,135.03,134.98, 134.98,135.07,135.25,135.75,137.07,137.35,137.44,138.07, 138.07,137.80,137.75,137.25) uu$y=c(39.878,39.749,39.490,39.296,39.200,39.135,38.909, 38.618,38.327,38.004,37.875,37.875,38.327,38.489, 38.812,39.006,39.232,39.587,39.943) ### plot raw data plot(uu$x, uu$y, type="l") #### cutoff: z1 = 39 h = 1:length(uu$x) w1 = which( uu$y>z1) g1 = list(x=uu$x[w1] , y=uu$y[w1] ) lines(g1, col='red') ############ notice the connecting line. ######### how can we avoid this? w2 = which(diff(w1)!=1) k = breakline.index(w1, w2) for(i in 1:length(k)) lines(uu$x[ k[[i]] ], uu$y[ k[[i]] ], col='blue') ###### see, line is broken correctly
### example with a vector of breaks h = 1:20 k = breakline.index(h, c(8, 14)) ######## select with a matrix of start-ends r1 = rbind(c(3,10), c(14, 18)) k = breakline.index(h, r1) j1 = seq(from=3, to=17, by=3) j2 = j1+5 ########## overlapping sequences r1 = cbind(j1, j2) k = breakline.index(h, r1) ###### example with coordinates #### some data: uu=list() uu$x=c(136.66,136.34,136.07,136.07,135.62,135.03,134.98, 134.98,135.07,135.25,135.75,137.07,137.35,137.44,138.07, 138.07,137.80,137.75,137.25) uu$y=c(39.878,39.749,39.490,39.296,39.200,39.135,38.909, 38.618,38.327,38.004,37.875,37.875,38.327,38.489, 38.812,39.006,39.232,39.587,39.943) ### plot raw data plot(uu$x, uu$y, type="l") #### cutoff: z1 = 39 h = 1:length(uu$x) w1 = which( uu$y>z1) g1 = list(x=uu$x[w1] , y=uu$y[w1] ) lines(g1, col='red') ############ notice the connecting line. ######### how can we avoid this? w2 = which(diff(w1)!=1) k = breakline.index(w1, w2) for(i in 1:length(k)) lines(uu$x[ k[[i]] ], uu$y[ k[[i]] ], col='blue') ###### see, line is broken correctly
Interactive Button Documentation for RPMG codes
butdoc(tag, doc, NEW = FALSE)
butdoc(tag, doc, NEW = FALSE)
tag |
character vector of tags |
doc |
character vector of (short) explanations |
NEW |
logical, TRUE = open new device |
This is used in conjunction with interactive codes that employ RPMG
Side Effects
Jonathan M. Lees<[email protected]>
chooser
ALLLABS = c( "DONE","REFRESH","EPS","LINE","DECIM","MAP","SURF","TRACE","TTC","CITY","TRcol", "STName","Pick","ZOOM","UNZOOM","IDARR","FILT","UnFILT","P-GEN") N = length(ALLLABS) DOC = rep(NA, length=N) DOC[1] = "Quick and return to calling program" DOC[2] = "refresh screen" DOC[3] = "Postscript plot" DOC[4] = "draw a line (even number of clicks)" DOC[5] = "Decimate the traces" DOC[6] = "Make a map with great circles" DOC[7] = "Draw a set of surface wave arrivals" DOC[8] = "Toggle drawing of traces" DOC[9] = "Travel Time Curves" DOC[10] = "put random cities on X-axis" DOC[11] = "toggle plotting traces with colors" DOC[12] = "put station names on X-axis" DOC[13] = "Pick arrivals on one trace" DOC[14] = "Zoom display (need two clicks on screen)" DOC[15] = "unzoom to original display" DOC[16] = "Identify traces" DOC[17] = "Fitler traces with a set of filters provided" DOC[18] = "Unfilter traces to original display" DOC[19] = "Run PICK.GEN on selected traces: select on the tags at X-axis" butdoc(ALLLABS, DOC, NEW=FALSE)
ALLLABS = c( "DONE","REFRESH","EPS","LINE","DECIM","MAP","SURF","TRACE","TTC","CITY","TRcol", "STName","Pick","ZOOM","UNZOOM","IDARR","FILT","UnFILT","P-GEN") N = length(ALLLABS) DOC = rep(NA, length=N) DOC[1] = "Quick and return to calling program" DOC[2] = "refresh screen" DOC[3] = "Postscript plot" DOC[4] = "draw a line (even number of clicks)" DOC[5] = "Decimate the traces" DOC[6] = "Make a map with great circles" DOC[7] = "Draw a set of surface wave arrivals" DOC[8] = "Toggle drawing of traces" DOC[9] = "Travel Time Curves" DOC[10] = "put random cities on X-axis" DOC[11] = "toggle plotting traces with colors" DOC[12] = "put station names on X-axis" DOC[13] = "Pick arrivals on one trace" DOC[14] = "Zoom display (need two clicks on screen)" DOC[15] = "unzoom to original display" DOC[16] = "Identify traces" DOC[17] = "Fitler traces with a set of filters provided" DOC[18] = "Unfilter traces to original display" DOC[19] = "Run PICK.GEN on selected traces: select on the tags at X-axis" butdoc(ALLLABS, DOC, NEW=FALSE)
Choose an option from a selection
chooser(opts=c(1, 2, 5, 10, 15, 20) , ncol=5, nsel=NA, newdev=TRUE, STAY=FALSE, cols="red", main="", newplot=TRUE, xlim=c(0,1), ylim=c(0,1), just="CEN", ... )
chooser(opts=c(1, 2, 5, 10, 15, 20) , ncol=5, nsel=NA, newdev=TRUE, STAY=FALSE, cols="red", main="", newplot=TRUE, xlim=c(0,1), ylim=c(0,1), just="CEN", ... )
opts |
list of options |
ncol |
number of columns |
nsel |
number of selections |
newdev |
logical, TRUE=start new device, default=TRUE |
STAY |
logical, TRUE=keep same device when done, default=FALSE |
cols |
colors for buttons, default = pastel.col(N) |
main |
title for screen (maybe instructions for picking) |
newplot |
logical, TRUE means start a new plot |
xlim |
xlim on the plot |
ylim |
ylim on the plot |
just |
character, justification in box, one of CEN, LEFT, RIGHT |
... |
additional parameters from par, used for font, cex, etc... |
Used for interactive selections of numeric or other options. If the input vector is all numeric, a numeric value is returned. If, on the other hand, the input is mixed or character, a character vector is returned. If the selection number nsel is left blank, it is set at 1. If it is specified, selection can be truncated by clicking the right mouse.
vector of selections.
Jonathan M. Lees<jonathan.lees.edu>
locator
## Not run: k = letters[1:26] pk = chooser(opts=k , nsel=3 ) print(pk) k = c( 1:26, letters[1:26]) pk = chooser(opts=k , nsel=3 ) print(pk) k = 1:12 pk = chooser(opts=k , nsel=3 ) print(pk) ################## plot(runif(10, 1, 100), runif(10, 1, 100), type='n') APAL = c('tan2','red2','lightpink3','chocolate4','blue3','thistle4', 'lightcyan4', 'orangered1','purple4','darkred', 'dodgerblue1','gold3','chartreuse', 'sienna4') ## nchar( APAL ) wm = which.max(nchar( APAL )) swidth = strwidth(APAL[wm]) upar = par("usr") mhgt = sum( strheight(APAL )+0.5*strheight(APAL )) mwid = max( strwidth(APAL) ) mwid = mwid + 0.05*mwid chooser(opts=APAL , ncol=1, nsel=NA, newdev=FALSE, STAY=TRUE, newplot=FALSE, xlim=c(upar[1], upar[1]+mwid) , ylim=c( (upar[4]-mhgt),upar[4]) , main="" ) ## End(Not run)
## Not run: k = letters[1:26] pk = chooser(opts=k , nsel=3 ) print(pk) k = c( 1:26, letters[1:26]) pk = chooser(opts=k , nsel=3 ) print(pk) k = 1:12 pk = chooser(opts=k , nsel=3 ) print(pk) ################## plot(runif(10, 1, 100), runif(10, 1, 100), type='n') APAL = c('tan2','red2','lightpink3','chocolate4','blue3','thistle4', 'lightcyan4', 'orangered1','purple4','darkred', 'dodgerblue1','gold3','chartreuse', 'sienna4') ## nchar( APAL ) wm = which.max(nchar( APAL )) swidth = strwidth(APAL[wm]) upar = par("usr") mhgt = sum( strheight(APAL )+0.5*strheight(APAL )) mwid = max( strwidth(APAL) ) mwid = mwid + 0.05*mwid chooser(opts=APAL , ncol=1, nsel=NA, newdev=FALSE, STAY=TRUE, newplot=FALSE, xlim=c(upar[1], upar[1]+mwid) , ylim=c( (upar[4]-mhgt),upar[4]) , main="" ) ## End(Not run)
generate circle coordinates for plotting
circle(n = 1, ang1=0)
circle(n = 1, ang1=0)
n |
number of points |
ang1 |
starting angle (degrees) |
List
x |
coordinates |
y |
coordinates |
Jonathan M. Lees <[email protected]>
j = circle(26) plot(j)
j = circle(26) plot(j)
Graded Color Scale position by locator
ColorScale(z, loc = list(x = 0, y = 0), thick=1, len=1, offset=.2, col = rainbow(100),border='black', gradcol='black',numbcol='black', unitscol='black', units = "", SIDE = 1, font = 1, fontindex =1, cex=1)
ColorScale(z, loc = list(x = 0, y = 0), thick=1, len=1, offset=.2, col = rainbow(100),border='black', gradcol='black',numbcol='black', unitscol='black', units = "", SIDE = 1, font = 1, fontindex =1, cex=1)
z |
values to be scaled |
loc |
x-y location boundary of plotting area, user coordinates |
thick |
width of scale bar in inches |
len |
length of scale bar in inches |
offset |
offset from border, in inches |
col |
color palette |
border |
color for border of scale, NA=do not plot |
gradcol |
color for gradiation marks of scale, NA=do not plot |
numbcol |
color for number values of scale, NA=do not plot |
unitscol |
color for units character string, NA=do not plot |
units |
character, units for values |
SIDE |
side, 1,2,3,4 as in axis |
font |
vfont number |
fontindex |
font index number |
cex |
character expansion, see par for details |
Locations (loc) are given in User coordinates. The scale is plotted relative to the location provided in user coordinates and offset by so many inches outside that unit. to get a scale plotted on the interior of a plot, send ColorScale a rectangular box inside the plotting region and give it a 0 offset. All other measures are given in inches. To suppress the plotting of a particular item, indicate NA for its color.
Since the list of the bounding box is returned, this can be used to modify the text, e.g. change the way the units are displayed.
list Graphical Side effects and list of bounding box for color scale:
x |
x coordinates of box |
y |
y coordinates of box |
Jonathan M. Lees<[email protected]>
HOZscale
data(volcano) d = dim(volcano) x=seq(from=1,by=1, length=d[1]+1) y=seq(from=1,by=1, length=d[2]+1) plot(range(x), range(y), type='n', asp=1, ann=FALSE, axes=FALSE) image(x=x, y=y, z=volcano, col = rainbow(100), add=TRUE) z=volcano ColorScale(volcano, loc=list(x=range(x), y=range(y)) , col = rainbow(100), units = "Elev:m", font = 1, SIDE = 1) ColorScale(volcano, loc=list(x=range(x), y=range(y)) , col = rainbow(100), units = "Elev:m", font = 1, SIDE = 2) ColorScale(volcano, loc=list(x=range(x), y=range(y)) , col = rainbow(100), units = "Elev:m", font = 1, SIDE = 3) ColorScale(volcano, loc=list(x=range(x), y=range(y)) , col = rainbow(100), units = "Elev:m", font = 1, SIDE = 4) plot(range(x), range(y), type='n', asp=1, ann=FALSE, axes=FALSE) ## image(x=x, y=y, z=volcano, col = rainbow(100), add=TRUE) XAX = pretty(x) XAX = XAX[XAX>=min(x) & XAX<=max(x)] axis(1, at=XAX, pos=y[1]) YAX = pretty(y) YAX = YAX[YAX>=min(y) & YAX<=max(y)] axis(2, at=YAX, pos=x[1]) rect(x[1], y[1], max(x), max(y)) ColorScale(volcano, loc=list(x=range(x), y=range(y)) ,offset=.8, col = rainbow(100), units = "Elev:m", font = 2, SIDE = 1) ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.8 , col = rainbow(100), units = "Elev:m", font = 1, fontindex = 2,SIDE = 2) ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.2 , col = rainbow(100), units = "Elev:m", font = 1, fontindex = 3, SIDE = 3) ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.2 , col = rainbow(100), units = "Elev:m", font = 2, fontindex = 3, SIDE = 4) plot(range(x), range(y), type='n', asp=1, ann=FALSE, axes=FALSE) ## image(x=x, y=y, z=volcano, col = rainbow(100), add=TRUE) XAX = pretty(x) XAX = XAX[XAX>=min(x) & XAX<=max(x)] axis(1, at=XAX, pos=y[1]) YAX = pretty(y) YAX = YAX[YAX>=min(y) & YAX<=max(y)] axis(2, at=YAX, pos=x[1]) rect(x[1], y[1], max(x), max(y)) ColorScale(volcano, loc=list(x=range(x), y=range(y)) , offset=.8, gradcol= NA, col = rainbow(100), units = "Elev:m", font = 2, SIDE = 1) ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.8 ,numbcol = NA, col = rainbow(100), units = "Elev:m", font = 1, fontindex = 2,SIDE = 2) ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.2 ,unitscol = NA, col = rainbow(100), units = "Elev:m", font = 1, fontindex = 3, SIDE = 3) ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.2 ,border = NA, gradcol = 'black', numbcol = 'blue', unitscol = 'purple', col = rainbow(100), units = "Elev:m", font = 2, fontindex = 3, SIDE = 4) ########################### plot(range(x), range(y), type='n', asp=1, ann=FALSE, axes=FALSE) ## image(x=x, y=y, z=volcano, col = rainbow(100), add=TRUE) XAX = pretty(x) XAX = XAX[XAX>=min(x) & XAX<=max(x)] axis(1, at=XAX, pos=y[1]) YAX = pretty(y) YAX = YAX[YAX>=min(y) & YAX<=max(y)] axis(2, at=YAX, pos=x[1]) rect(x[1], y[1], max(x), max(y)) B = ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.2 ,border = NA, gradcol = NA, numbcol = NA, unitscol = NA, col = rainbow(100), units = "Elev:m", font = 2, fontindex = 3, SIDE = 3) text(mean(B$x), B$y[2], "scaled data", pos=3, xpd=TRUE) text(B$x[1], mean(B$y), min(volcano), pos=2, xpd=TRUE) text(B$x[2], mean(B$y), max(volcano), pos=4, xpd=TRUE) ########################### dark background par(fg="white") par(bg="black") par(col.axis="white", col.lab="white", col.main="white", col.sub="white") plot(range(x), range(y), type='n', asp=1, ann=FALSE, axes=FALSE, fg='white' ) image(x=x, y=y, z=volcano, col = rainbow(100), add=TRUE) XAX = pretty(x) XAX = XAX[XAX>=min(x) & XAX<=max(x)] axis(1, at=XAX, pos=y[1]) YAX = pretty(y) YAX = YAX[YAX>=min(y) & YAX<=max(y)] axis(2, at=YAX, pos=x[1]) rect(x[1], y[1], max(x), max(y), border='white') ColorScale(volcano, loc=list(x=range(x), y=range(y)) ,offset=.6, gradcol= 'black', unitscol =rgb(.9, .9, 1) , numbcol =rgb(.9, 1, .9) , border="white", col = rainbow(100), units = "Elev:m", font = 2, fontindex = 3, SIDE = 1) ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.8 ,numbcol= rgb(1, .85, .85) , col = rainbow(100), units = "Elev:m", font = 1, fontindex = 2,SIDE = 2) ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.2,unitscol = NA, col = rainbow(100), units = "Elev:m", font = 1, fontindex = 3, SIDE = 3) ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.2 ,border = NA, gradcol = 'white', numbcol = 'blue', unitscol = 'purple', col = rainbow(100), units = "Elev:m", font = 2, fontindex = 3, SIDE = 4) plot(range(x), range(y), type='n', asp=1, ann=FALSE, axes=FALSE, fg='white' ) XAX = pretty(x) XAX = XAX[XAX>=min(x) & XAX<=max(x)] axis(1, at=XAX, pos=y[1]) YAX = pretty(y) YAX = YAX[YAX>=min(y) & YAX<=max(y)] axis(2, at=YAX, pos=x[1]) rect(x[1], y[1], max(x), max(y), border='black') ColorScale(volcano, loc=list(x=c(20, 40), y=c(10, 40)), thick=.2, offset=0 , col = rainbow(100), units = "Elev:m", font = 1, fontindex = 2,SIDE = 2, cex=.5)
data(volcano) d = dim(volcano) x=seq(from=1,by=1, length=d[1]+1) y=seq(from=1,by=1, length=d[2]+1) plot(range(x), range(y), type='n', asp=1, ann=FALSE, axes=FALSE) image(x=x, y=y, z=volcano, col = rainbow(100), add=TRUE) z=volcano ColorScale(volcano, loc=list(x=range(x), y=range(y)) , col = rainbow(100), units = "Elev:m", font = 1, SIDE = 1) ColorScale(volcano, loc=list(x=range(x), y=range(y)) , col = rainbow(100), units = "Elev:m", font = 1, SIDE = 2) ColorScale(volcano, loc=list(x=range(x), y=range(y)) , col = rainbow(100), units = "Elev:m", font = 1, SIDE = 3) ColorScale(volcano, loc=list(x=range(x), y=range(y)) , col = rainbow(100), units = "Elev:m", font = 1, SIDE = 4) plot(range(x), range(y), type='n', asp=1, ann=FALSE, axes=FALSE) ## image(x=x, y=y, z=volcano, col = rainbow(100), add=TRUE) XAX = pretty(x) XAX = XAX[XAX>=min(x) & XAX<=max(x)] axis(1, at=XAX, pos=y[1]) YAX = pretty(y) YAX = YAX[YAX>=min(y) & YAX<=max(y)] axis(2, at=YAX, pos=x[1]) rect(x[1], y[1], max(x), max(y)) ColorScale(volcano, loc=list(x=range(x), y=range(y)) ,offset=.8, col = rainbow(100), units = "Elev:m", font = 2, SIDE = 1) ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.8 , col = rainbow(100), units = "Elev:m", font = 1, fontindex = 2,SIDE = 2) ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.2 , col = rainbow(100), units = "Elev:m", font = 1, fontindex = 3, SIDE = 3) ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.2 , col = rainbow(100), units = "Elev:m", font = 2, fontindex = 3, SIDE = 4) plot(range(x), range(y), type='n', asp=1, ann=FALSE, axes=FALSE) ## image(x=x, y=y, z=volcano, col = rainbow(100), add=TRUE) XAX = pretty(x) XAX = XAX[XAX>=min(x) & XAX<=max(x)] axis(1, at=XAX, pos=y[1]) YAX = pretty(y) YAX = YAX[YAX>=min(y) & YAX<=max(y)] axis(2, at=YAX, pos=x[1]) rect(x[1], y[1], max(x), max(y)) ColorScale(volcano, loc=list(x=range(x), y=range(y)) , offset=.8, gradcol= NA, col = rainbow(100), units = "Elev:m", font = 2, SIDE = 1) ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.8 ,numbcol = NA, col = rainbow(100), units = "Elev:m", font = 1, fontindex = 2,SIDE = 2) ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.2 ,unitscol = NA, col = rainbow(100), units = "Elev:m", font = 1, fontindex = 3, SIDE = 3) ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.2 ,border = NA, gradcol = 'black', numbcol = 'blue', unitscol = 'purple', col = rainbow(100), units = "Elev:m", font = 2, fontindex = 3, SIDE = 4) ########################### plot(range(x), range(y), type='n', asp=1, ann=FALSE, axes=FALSE) ## image(x=x, y=y, z=volcano, col = rainbow(100), add=TRUE) XAX = pretty(x) XAX = XAX[XAX>=min(x) & XAX<=max(x)] axis(1, at=XAX, pos=y[1]) YAX = pretty(y) YAX = YAX[YAX>=min(y) & YAX<=max(y)] axis(2, at=YAX, pos=x[1]) rect(x[1], y[1], max(x), max(y)) B = ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.2 ,border = NA, gradcol = NA, numbcol = NA, unitscol = NA, col = rainbow(100), units = "Elev:m", font = 2, fontindex = 3, SIDE = 3) text(mean(B$x), B$y[2], "scaled data", pos=3, xpd=TRUE) text(B$x[1], mean(B$y), min(volcano), pos=2, xpd=TRUE) text(B$x[2], mean(B$y), max(volcano), pos=4, xpd=TRUE) ########################### dark background par(fg="white") par(bg="black") par(col.axis="white", col.lab="white", col.main="white", col.sub="white") plot(range(x), range(y), type='n', asp=1, ann=FALSE, axes=FALSE, fg='white' ) image(x=x, y=y, z=volcano, col = rainbow(100), add=TRUE) XAX = pretty(x) XAX = XAX[XAX>=min(x) & XAX<=max(x)] axis(1, at=XAX, pos=y[1]) YAX = pretty(y) YAX = YAX[YAX>=min(y) & YAX<=max(y)] axis(2, at=YAX, pos=x[1]) rect(x[1], y[1], max(x), max(y), border='white') ColorScale(volcano, loc=list(x=range(x), y=range(y)) ,offset=.6, gradcol= 'black', unitscol =rgb(.9, .9, 1) , numbcol =rgb(.9, 1, .9) , border="white", col = rainbow(100), units = "Elev:m", font = 2, fontindex = 3, SIDE = 1) ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.8 ,numbcol= rgb(1, .85, .85) , col = rainbow(100), units = "Elev:m", font = 1, fontindex = 2,SIDE = 2) ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.2,unitscol = NA, col = rainbow(100), units = "Elev:m", font = 1, fontindex = 3, SIDE = 3) ColorScale(volcano, loc=list(x=range(x), y=range(y)), offset=.2 ,border = NA, gradcol = 'white', numbcol = 'blue', unitscol = 'purple', col = rainbow(100), units = "Elev:m", font = 2, fontindex = 3, SIDE = 4) plot(range(x), range(y), type='n', asp=1, ann=FALSE, axes=FALSE, fg='white' ) XAX = pretty(x) XAX = XAX[XAX>=min(x) & XAX<=max(x)] axis(1, at=XAX, pos=y[1]) YAX = pretty(y) YAX = YAX[YAX>=min(y) & YAX<=max(y)] axis(2, at=YAX, pos=x[1]) rect(x[1], y[1], max(x), max(y), border='black') ColorScale(volcano, loc=list(x=c(20, 40), y=c(10, 40)), thick=.2, offset=0 , col = rainbow(100), units = "Elev:m", font = 1, fontindex = 2,SIDE = 2, cex=.5)
Shows and image of colors and allows one to choose a color and see what it looks like in swath with different backgrounds.
colwheel(v = 1, BACK = "black")
colwheel(v = 1, BACK = "black")
v |
v, from hsv color scheme |
BACK |
starting background color |
vector of RGB colors in hex format.
Jonathan M. Lees<[email protected]>
hsv, VVwheel, wheelrgb, SHOWPAL.A
## Not run: colwheel(v = 1, BACK = "black") colwheel(v = 1, BACK = "white") ## End(Not run)
## Not run: colwheel(v = 1, BACK = "black") colwheel(v = 1, BACK = "white") ## End(Not run)
dump out an R assignemnt statement to the screen
cprint(a)
cprint(a)
a |
R object |
side effects
Jonathan M. Lees<[email protected]>
x = 10 cprint(x)
x = 10 cprint(x)
Calculate nice scale to use at the end of a plot. Use as an alternative to magicaxis.
endSCALE(arange, digits = 3)
endSCALE(arange, digits = 3)
arange |
2-vector of bounds |
digits |
number of digits to use |
The function returns information for plotting a nice bounds axis similar to MATLAB plotting style.
character vector: min, max, exponent
If the bounds span multiple orders of magnitude, may want to make adjustments (like setting a negative exponent bound to zero)
Jonathan M. Lees<[email protected]>
plotwlet
M = 1e-19 m = M for(i in 1:10) { z = c( rnorm(1)*m , rnorm(1)*M ) print(z) print( endSCALE(z) ) ########## use in plotting: x = seq(from=0, by=0.01, length=200) a = 10000*rnorm(length(x)) old.par <- par(no.readonly = TRUE) ############ make room on the right margin MAI = par("mai") MAI[4] = MAI[2] par(mfrow=c(2,1)) par(mai=MAI) par(xaxs='i', yaxs='i') plot(x,a, type='l') axtrace = range(a) Elabs = endSCALE(axtrace) exp = parse(text = Elabs[3]) axis(4, at=axtrace , labels=Elabs[1:2] , pos=max(x), tick=TRUE , line=0.5, cex.axis=0.8,las=2) mtext(exp, side = 3, at = max(x), line=0.5, adj=-1 , cex=0.8) mtext("m/s", side = 4, at =mean(axtrace) , line=0.5 , cex=0.8 ,las=1 ) a = rnorm(length(x))/100000 plot(x,a, type='l') axtrace = range(a) Elabs = endSCALE(axtrace) exp = parse(text = Elabs[3]) axis(4, at=axtrace , labels=Elabs[1:2] , pos=max(x), tick=TRUE , line=0.5, cex.axis=0.8,las=2) mtext(exp, side = 3, at = max(x), line=0.5, adj=-1 , cex=0.8) mtext("m/s", side = 4, at =mean(axtrace) , line=0.5 , cex=0.8 ,las=1 ) par(old.par) }
M = 1e-19 m = M for(i in 1:10) { z = c( rnorm(1)*m , rnorm(1)*M ) print(z) print( endSCALE(z) ) ########## use in plotting: x = seq(from=0, by=0.01, length=200) a = 10000*rnorm(length(x)) old.par <- par(no.readonly = TRUE) ############ make room on the right margin MAI = par("mai") MAI[4] = MAI[2] par(mfrow=c(2,1)) par(mai=MAI) par(xaxs='i', yaxs='i') plot(x,a, type='l') axtrace = range(a) Elabs = endSCALE(axtrace) exp = parse(text = Elabs[3]) axis(4, at=axtrace , labels=Elabs[1:2] , pos=max(x), tick=TRUE , line=0.5, cex.axis=0.8,las=2) mtext(exp, side = 3, at = max(x), line=0.5, adj=-1 , cex=0.8) mtext("m/s", side = 4, at =mean(axtrace) , line=0.5 , cex=0.8 ,las=1 ) a = rnorm(length(x))/100000 plot(x,a, type='l') axtrace = range(a) Elabs = endSCALE(axtrace) exp = parse(text = Elabs[3]) axis(4, at=axtrace , labels=Elabs[1:2] , pos=max(x), tick=TRUE , line=0.5, cex.axis=0.8,las=2) mtext(exp, side = 3, at = max(x), line=0.5, adj=-1 , cex=0.8) mtext("m/s", side = 4, at =mean(axtrace) , line=0.5 , cex=0.8 ,las=1 ) par(old.par) }
extract remainder for floating point numbers
fmod(k, m)
fmod(k, m)
k |
floating point number |
m |
divisor number |
returns remainder after dividing out the divisor part:j = floor(k/m)
a = k-m*j
return(a)
Jonathan M. Lees <[email protected]>
### degrees after removing extraneous 2*pi j = 540.23 fmod(j, 360)
### degrees after removing extraneous 2*pi j = 540.23 fmod(j, 360)
Get Color Palette
Gcols(plow = 10, phi = 10, N = 100, pal = "rainbow", mingray = 0.5)
Gcols(plow = 10, phi = 10, N = 100, pal = "rainbow", mingray = 0.5)
plow |
lowest number for color selection |
phi |
highest number for color selection |
N |
number of colors |
pal |
color palette name |
mingray |
lower end is blanked out and replaced by gray |
c(LOW , Z, HI) color palette
Jonathan M. Lees<jonathan.lees.edu>
tomo.colors, shade.col
TPALS = c("rainbow", "topo.colors", "terrain.colors", "heat.colors", "tomo.col") pal = Gcols(plow=5, phi=0, N=100, pal=TPALS[3])
TPALS = c("rainbow", "topo.colors", "terrain.colors", "heat.colors", "tomo.col") pal = Gcols(plow=5, phi=0, N=100, pal=TPALS[3])
Get a member of a list
getmem(v, mem = 1)
getmem(v, mem = 1)
v |
vector |
mem |
element in vector |
Used in conjunction with apply
vector of members of a list
Jonathan M. Lees<[email protected]>
z = list() for(i in 1:10) { z[[i]] = round(10*runif(10)) } y = as.vector(unlist(lapply(z, getmem, 6)))
z = list() for(i in 1:10) { z[[i]] = round(10*runif(10)) } y = as.vector(unlist(lapply(z, getmem, 6)))
Give information on how to set up Personal Color Palettes
helpcolors()
helpcolors()
Side effects
Jonathan M. Lees<[email protected]>
palette
helpcolors()
helpcolors()
Add horizontal color scale to existing plot.
HOZscale(z, col, units="", SIDE=1, s1=.6, s2=0.95, format=1, digits=3, cex=1, cex.units=1)
HOZscale(z, col, units="", SIDE=1, s1=.6, s2=0.95, format=1, digits=3, cex=1, cex.units=1)
z |
image matrix |
col |
color palette |
units |
character string, units |
SIDE |
Side of the plot |
s1 |
percent of margin for bottom |
s2 |
percent of margin for top |
format |
Format: 1 for normal number, 2 for exponential notation |
digits |
Significant digits |
cex |
Character expansion for the numeric values. |
cex.units |
Character expansion for the units. |
Vector of rectangle coordinates and z-values: c(xmin,ymin, xmax, ymax, Z-min, Z-max)
Jonathan M. Lees<jonathan.lees.edu>
data(volcano) image(volcano, col=terrain.colors(100)) HOZscale(volcano,terrain.colors(100) , units = "", SIDE = 1, s1 = 0.4, s2 = 0.95) plot(1:10, 1:10, type='n') j = c(runif(1, -10, 10) , runif(1, 20, 10000) ) ### example showing scale above and below HOZscale(j, terrain.colors(100), units="hi", SIDE=3, s1=.4, s2=0.6, format=2, digits=2, cex.units = 1.2, cex=1.2) j = c(runif(1, -10, 10)/1000 , runif(1, 1, 10) ) HOZscale(j, terrain.colors(100), units="hi", SIDE=1, s1=.6, s2=0.8, format=2, digits=2, cex.units = 0.8)
data(volcano) image(volcano, col=terrain.colors(100)) HOZscale(volcano,terrain.colors(100) , units = "", SIDE = 1, s1 = 0.4, s2 = 0.95) plot(1:10, 1:10, type='n') j = c(runif(1, -10, 10) , runif(1, 20, 10000) ) ### example showing scale above and below HOZscale(j, terrain.colors(100), units="hi", SIDE=3, s1=.4, s2=0.6, format=2, digits=2, cex.units = 1.2, cex=1.2) j = c(runif(1, -10, 10)/1000 , runif(1, 1, 10) ) HOZscale(j, terrain.colors(100), units="hi", SIDE=1, s1=.6, s2=0.8, format=2, digits=2, cex.units = 0.8)
Add tics and levels to color scale for am image plot.
HOZtics(HOZ, side = 1)
HOZtics(HOZ, side = 1)
HOZ |
Output coordinates of HOZscale |
side |
1=above, 2=below |
The levels are determined via the pretty function.
Jonathan M. Lees<[email protected]>
ColorScale
pal1 = terrain.colors(100) Z = c(1,40) plot(c(0,1), c(0,1) ) hs = HOZscale(Z, col=pal1) HOZtics(hs, side=1)
pal1 = terrain.colors(100) Z = c(1,40) plot(c(0,1), c(0,1) ) hs = HOZscale(Z, col=pal1) HOZtics(hs, side=1)
Locator function with set parameters
ilocator(N=1, COL=1, NUM=FALSE, YN=NULL, style=0)
ilocator(N=1, COL=1, NUM=FALSE, YN=NULL, style=0)
N |
number of points to locate |
COL |
color |
NUM |
number of points |
YN |
number of windows to span for lines |
style |
0,1,2 for differnt style of plotting vertical lines |
if the window is divided into YN horizontal regions, style =2 will plot segments only within regions based on y-value of locator().
list:
x |
x-locations |
y |
y-locations |
n |
number of points |
Jonathan M. Lees<jonathan.lees.edu>
locator
plot(c(0,1), c(0,1), type='n') for(i in 1:5) { abline(h=i/6) } ilocator(N=3, COL = 1, NUM = 4, YN = 6, style = 2)
plot(c(0,1), c(0,1), type='n') for(i in 1:5) { abline(h=i/6) } ilocator(N=3, COL = 1, NUM = 4, YN = 6, style = 2)
Given I index get ix,iy, iz for three dimensional grids.
itoxyz(i, nx, ny, nz)
itoxyz(i, nx, ny, nz)
i |
index to long vector |
nx |
number of blocks in x axis |
ny |
number of blocks in y axis |
nz |
number of blocks in z axis (layers) |
ix |
Index of X-array |
iy |
Index of Y-array |
iz |
Index of Z-array (layer) |
Jonathan M. Lees<jonathan.lees.edu>
xyztoi
itoxyz(24, 6, 6, 1) kpos = itoxyz(2443:2500 , 20, 20, 13)
itoxyz(24, 6, 6, 1) kpos = itoxyz(2443:2500 , 20, 20, 13)
Get file name and recreate plot on a png or pdf device. This program makes an attempt to keep the same size plot as viewed in the screen.
jpng(file='tmp', width = 8, height = 8,P = NULL, bg = "white") jpdf(file='tmp', width = 8, height = 8,P = NULL)
jpng(file='tmp', width = 8, height = 8,P = NULL, bg = "white") jpdf(file='tmp', width = 8, height = 8,P = NULL)
file |
png or pdf: will be added as a suffix, if needed |
width |
width, inches |
height |
height, inches |
P |
vector to fix the size, c(width, height) |
bg |
background color (default="transparent") |
If P=c(10,12) is missing or NULL, program will attempt to use current plotting region via par to duplicated the size of the postscript device. Must close this device with dev.off() to finish. If either w or h are provided they will override the values in vector P.
If the standard suffix (png or pdf) are provided the file will be set. If these are omitted, they will be added to the given name according to the local.file function.
Graphical Side Effect
Jonathan M. Lees<jonathan.lees.edu>
par, postscript, device
## Not run: jjj = local.file('hi', 'png') x= rnorm(10) y= rnorm(10) plot(x,y) print('resize the current plot') jpng(jjj, width = 8, height = 8) plot(x,y) dev.off() jpdf("HiThere.pdf", width = 8, height = 8 ) plot(x,y) dev.off() jpng("HiThere.png", width = 8, height = 8 , bg='red' ) plot(x,y) dev.off() ## End(Not run)
## Not run: jjj = local.file('hi', 'png') x= rnorm(10) y= rnorm(10) plot(x,y) print('resize the current plot') jpng(jjj, width = 8, height = 8) plot(x,y) dev.off() jpdf("HiThere.pdf", width = 8, height = 8 ) plot(x,y) dev.off() jpng("HiThere.png", width = 8, height = 8 , bg='red' ) plot(x,y) dev.off() ## End(Not run)
Get file name and recreate plot on a postsctipt device. This program makes an attempt to keep the same size plot as viewed in the screen.
jpostscript(file=NULL, P=NULL, w=NULL, h=NULL)
jpostscript(file=NULL, P=NULL, w=NULL, h=NULL)
file |
Postscript file name, eps will be added as a suffix |
P |
vector to fix the size, c(width, height) |
w |
width, inches |
h |
height, inches |
If P=c(10,12) is missing or NULL, program will attempt to use current plotting region via par to duplicated the size of the postscript device. Must close this device with dev.off() to finish. If either w or h are provided they will override the values in vector P.
Graphical Side Effect
Jonathan M. Lees<jonathan.lees.edu>
par, postscript, device
## Not run: jjj = local.file('hi', 'eps') x= rnorm(10) y= rnorm(10) plot(x,y) print('resize the current plot') jpostscript(jjj) plot(x,y) dev.off() jpostscript("HiThere", P=c(7,7) ) plot(x,y) dev.off() jpostscript("HiThere", P=c(7,7), w=10 ) plot(x,y) dev.off() ## End(Not run)
## Not run: jjj = local.file('hi', 'eps') x= rnorm(10) y= rnorm(10) plot(x,y) print('resize the current plot') jpostscript(jjj) plot(x,y) dev.off() jpostscript("HiThere", P=c(7,7) ) plot(x,y) dev.off() jpostscript("HiThere", P=c(7,7), w=10 ) plot(x,y) dev.off() ## End(Not run)
Put Labels (A,B, C...) on corners of figures
label.it(a = "", corn = 1, ...)
label.it(a = "", corn = 1, ...)
a |
letters |
corn |
corner |
... |
graphical parameters passed from par |
Graphical Side effects
Jonathan M. Lees<[email protected]>
par(mfrow=c(2,2)) for(i in 1:4) { plot(rnorm(5), rnorm(5)) label.it(letters[i],1) }
par(mfrow=c(2,2)) for(i in 1:4) { plot(rnorm(5), rnorm(5)) label.it(letters[i],1) }
Get a name for a local file for writing ascii files or postscript output. This code checks to see if file exists and if so it increments a counter int he name.
local.file(pref, suf)
local.file(pref, suf)
pref |
prefix for file name |
suf |
suffix for file name |
File name is located in the current directory.
character string for new file name
Jonathan M. Lees<jonathan.lees.edu>
psfile = local.file("JML", "eps")
psfile = local.file("JML", "eps")
Creates 2D matrices for accessing images and 2D matrices
meshgrid(a, b)
meshgrid(a, b)
a |
x vector components |
b |
y vector components |
returns outer product of x-compnents and y-components for use as index arrays
x |
length(y) by length(x) matrix of x indicies |
y |
length(y) by length(x) matrix of y indicies |
Jonathan M. Lees<[email protected]>
meshgrid(1:5, 1:3)
meshgrid(1:5, 1:3)
Replot Function for SELBUT
OPTREPLOT(opts , ncol=5, sel=1, HOZ=TRUE, TOP=TRUE, cols="white", scol="black", bcol="white" , tcol="black", slwd=1, blwd=3, main="", xlim=c(0,1), ylim=c(0,1), cex=1, mpct = 0.1, newplot=TRUE)
OPTREPLOT(opts , ncol=5, sel=1, HOZ=TRUE, TOP=TRUE, cols="white", scol="black", bcol="white" , tcol="black", slwd=1, blwd=3, main="", xlim=c(0,1), ylim=c(0,1), cex=1, mpct = 0.1, newplot=TRUE)
opts |
character list of options |
ncol |
number of columns |
sel |
vector of selected options |
HOZ |
logical, TRUE=plot horizontally |
TOP |
logical, TRUE=plot top-down |
cols |
colors |
scol |
select box color |
bcol |
default box color |
tcol |
box text color |
slwd |
select box line width |
blwd |
default box line width |
main |
character title |
xlim |
x-limits in plotting region (user coordinates) |
ylim |
y-limits in plotting region (user coordinates) |
cex |
character expansion for text in boxes |
mpct |
percentage margin to leave between option boxes |
newplot |
logical, TRUE=new plot |
Used internally in SELBUT as a replotting function
list
M |
x,y matrix of grid |
dx |
delta x |
dy |
delta y |
rx |
range of x |
ry |
range of y |
Jonathan M. Lees<[email protected]>
SELBUT, swig
STDLAB=c("DONE", "QUIT", "zoom.out", "zoom.in", "SELBUT", "FILT", "UNFILT", "PSEL", "SGRAM", "WLET", "SPEC", "XTR" ) OPTREPLOT(STDLAB) XMCOL = setXMCOL() YN = OPTREPLOT(XMCOL, cols =XMCOL, tcol=grey(.8) , scol= "transparent", bcol= "transparent", mpct=0.05 ) YN = OPTREPLOT(XMCOL, cols =XMCOL, tcol=grey(.8) , scol= "transparent", bcol= "black", mpct=0.05 )
STDLAB=c("DONE", "QUIT", "zoom.out", "zoom.in", "SELBUT", "FILT", "UNFILT", "PSEL", "SGRAM", "WLET", "SPEC", "XTR" ) OPTREPLOT(STDLAB) XMCOL = setXMCOL() YN = OPTREPLOT(XMCOL, cols =XMCOL, tcol=grey(.8) , scol= "transparent", bcol= "transparent", mpct=0.05 ) YN = OPTREPLOT(XMCOL, cols =XMCOL, tcol=grey(.8) , scol= "transparent", bcol= "black", mpct=0.05 )
vector of pastel colors
pastel.colors(num, seed=0)
pastel.colors(num, seed=0)
num |
number of colors |
seed |
random number seed |
The seed is a value given so that the same pastel colors can be extracted with each subsequent call to the code.
vector of RGB hex colors
Jonathan M. Lees<[email protected]>
rainbow
pastel.colors(12) pastel.colors(12, seed=1 )
pastel.colors(12) pastel.colors(12, seed=1 )
Pick a SYSTEM color
pickcolors(COLLIST = colors(), BACK = "white")
pickcolors(COLLIST = colors(), BACK = "white")
COLLIST |
system colors |
BACK |
background for colors |
List of colors
Jonathan M. Lees<[email protected]>
syscolors
## Not run: ######## see named colors, excluding grey SYSCOL = colors() greys = grep('grey', SYSCOL) grays = grep('gray', SYSCOL) kolz = SYSCOL[-c(greys, grays) ] pickcolors(COLLIST = kolz, BACK = "white") ### or just one type SYSCOL = colors() blues = SYSCOL[grep('blue', SYSCOL) ] pickcolors(COLLIST = blues, BACK = "white") ## End(Not run)
## Not run: ######## see named colors, excluding grey SYSCOL = colors() greys = grep('grey', SYSCOL) grays = grep('gray', SYSCOL) kolz = SYSCOL[-c(greys, grays) ] pickcolors(COLLIST = kolz, BACK = "white") ### or just one type SYSCOL = colors() blues = SYSCOL[grep('blue', SYSCOL) ] pickcolors(COLLIST = blues, BACK = "white") ## End(Not run)
Color palette of n rainbow colors
rainbow.colors(n)
rainbow.colors(n)
n |
Nmber of colors desired |
rainbow.colors is set to match other color palette selections like topo.colors, terrain.colors
Character vector of n colors from the default rainbow palette.
Jonathan M. Lees <[email protected]>
topo.colors, terrain.colors, palette
rainbow.colors(100)
rainbow.colors(100)
Rescale a vector to fit in a certain range
RESCALE(x, nx1=0, nx2=1, minx=0, maxx=1)
RESCALE(x, nx1=0, nx2=1, minx=0, maxx=1)
x |
vector |
nx1 |
new minimum |
nx2 |
new maximum |
minx |
old min |
maxx |
old max |
Rescaling a vector, mostly used for graphics. If x does not vary, i.e. it is constant or minx and max are identical, the mean value of nx1 and nx2 is returned.
Scale version of x vector is returned.
Jonathan M. Lees<jonathan.lees.edu>
x = rnorm(10) RESCALE(x, 3, 9, min(x), max(x) )
x = rnorm(10) RESCALE(x, 3, 9, min(x), max(x) )
Create a set of buttons and associated geometry for RPMG
rowBUTTONS(labs, col = 6, pch = 4, cex=1, boxsize = -1)
rowBUTTONS(labs, col = 6, pch = 4, cex=1, boxsize = -1)
labs |
Vector of labels for the buttons running across the top and bottom of the plot |
col |
Optional vector of colors for the buttons |
pch |
Optional vector of symbols to be plotted in the center of the buttons |
cex |
optional character expansion for text |
boxsize |
optional box size for the buttons, default=-1 where the size is adjusted for string size |
rowBUTTONS is called after the R graphic has been created so the geometry of the buttons can be set. Subsequent calls to whichbutt use the geometry to determine which button has been selected. Some of the parameters chosen here are controlled by par-like parameters.
The function returns a list of buttons and the associated geometry.
N |
Number of Buttons |
labs |
Names of the Buttons |
x1 |
vector of left x-coordinates for the buttons |
x2 |
vector of right x-coordinates for the buttons |
y1 |
vector of top y-coordinates for the buttons |
y2 |
vector of bottom y-coordinates for the buttons |
rowBUTTONS uses the current plotting parameters from par() to set the geometry. If the window is resized, rowBUTTONS should be reset to extract correct button position. In interactive mode this is done each time the plot is refreshed.
Jake Anderson and Jonathan M. Lees<[email protected]>
whichbutt, par
####### create a plot plot(c(0,1), c(0,1)) ####### set the character vector of button labels mybutts = c("DONE", "REFRESH", "rainbow", "topo", "terrain", "CONT", "XSEC","PS" ) ######### set colors and plotting chars for buttons colabs = rep(1, length=length(mybutts)) pchlabs = rep(0,length(mybutts)) ####### create and set geometry for buttons: buttons = rowBUTTONS(mybutts, col=colabs, pch=pchlabs)
####### create a plot plot(c(0,1), c(0,1)) ####### set the character vector of button labels mybutts = c("DONE", "REFRESH", "rainbow", "topo", "terrain", "CONT", "XSEC","PS" ) ######### set colors and plotting chars for buttons colabs = rep(1, length=length(mybutts)) pchlabs = rep(0,length(mybutts)) ####### create and set geometry for buttons: buttons = rowBUTTONS(mybutts, col=colabs, pch=pchlabs)
the function adds to an existing plot in the lower left corner
see.pal(col)
see.pal(col)
col |
vector of colors |
Side Effects
Jonathan M. Lees<[email protected]>
see.pals
plot(c(0,1), c(0,1), type='n') see.pal(rainbow(100))
plot(c(0,1), c(0,1), type='n') see.pal(rainbow(100))
Select buttons interactively.
SELOPT(OPTS, onoff = -1, ncol=5, ocols = "white", cex=1, default="opt" )
SELOPT(OPTS, onoff = -1, ncol=5, ocols = "white", cex=1, default="opt" )
OPTS |
character list of buttons |
onoff |
which buttons are active, onoff=-1 turns all buttons off, onoff=0 turns all buttons on, any other vector is an index vector to selected options |
ncol |
number of columns, default = 5 |
ocols |
colors for plotting option boxes |
cex |
character expansion for text in boxes |
default |
default vector of options |
Used in swig. OPtions can be added, subtracted, deleted, or completely filled out based on interactive choice.
character list of selected options
Jonathan M. Lees<[email protected]>
OPTREPLOT, chooser
## Not run: STDLAB=c("DONE", "QUIT", "zoom.out", "zoom.in", "SELOPT", "FILT","UNFILT", "PSEL", "SGRAM", "WLET", "SPEC", "XTR" ) onoff = rep(0, length(STDLAB)) onoff[1:5] = 1 SELOPT(STDLAB, onoff=onoff) ### second option for selecting colors ###dev.new(width=12, height=12) scol = SELOPT(colors(), onoff=-1, ncol=15, ocols =colors(), cex=.6 ) ### old program SHOWPAL(scol, NAME=TRUE) ### show the options chosen from top to bottom OPTREPLOT(scol, cols=scol, scol="green", bcol="blue", slwd=15 ) ## End(Not run)
## Not run: STDLAB=c("DONE", "QUIT", "zoom.out", "zoom.in", "SELOPT", "FILT","UNFILT", "PSEL", "SGRAM", "WLET", "SPEC", "XTR" ) onoff = rep(0, length(STDLAB)) onoff[1:5] = 1 SELOPT(STDLAB, onoff=onoff) ### second option for selecting colors ###dev.new(width=12, height=12) scol = SELOPT(colors(), onoff=-1, ncol=15, ocols =colors(), cex=.6 ) ### old program SHOWPAL(scol, NAME=TRUE) ### show the options chosen from top to bottom OPTREPLOT(scol, cols=scol, scol="green", bcol="blue", slwd=15 ) ## End(Not run)
Sepia Color Palette
sepia.colors(n, k = 1) myhcl.colors(n, k = 260)
sepia.colors(n, k = 1) myhcl.colors(n, k = 260)
n |
Number of colors |
k |
Sepia starting color, hcl ending number |
There are two version of sepia in the code, each has a slightly different sepia end member.
vector of Octal color codes
Jonathan M. Lees<[email protected]>
tomo.colors, pastel.colors, syscolors, helpcolors
scol = sepia.colors(100) SHOWPAL(scol) see.pal(scol)
scol = sepia.colors(100) SHOWPAL(scol) see.pal(scol)
Uses colors predefined in geotouch
setXMCOL()
setXMCOL()
Vector of named colors
Jonathan M. Lees<[email protected]>
XMCOL=setXMCOL()
XMCOL=setXMCOL()
Create a color palette with two end member colors
shade.col(n, acol = c(1, 0, 0), bcol = c(1, 1, 1))
shade.col(n, acol = c(1, 0, 0), bcol = c(1, 1, 1))
n |
number of desired colors |
acol |
rgb, starting color |
bcol |
rgb, ending color |
Linear interpolation from color1 to color 2.
color vector
Jonathan M. Lees<jonathan.lees.edu>
rainbow, tomo.col
## color palette from red to white shade.col(100, acol = c(1, 0, 0), bcol = c(1, 1, 1))
## color palette from red to white shade.col(100, acol = c(1, 0, 0), bcol = c(1, 1, 1))
Show a palette of colors as a bar
SHOWPAL( COLLIST , NAME = FALSE, NUM=FALSE, ncol = 5, BACK="transparent")
SHOWPAL( COLLIST , NAME = FALSE, NUM=FALSE, ncol = 5, BACK="transparent")
COLLIST |
vector of colors |
NAME |
name of palette |
NUM |
logical, TRUE=show index number |
ncol |
number of colors |
BACK |
Background color, default=NULL |
Graphical Side Effects
Jonathan M. Lees<[email protected]>
see.pals, help.pal , plotpal , helpcolors
########## make a large screen for a lot of colors ### dev.new(width=12, height=12) SHOWPAL(colors(), ncol=15, NAME=FALSE) gcol = setXMCOL() SHOWPAL(gcol, ncol=10, NAME=TRUE) #### show index: SHOWPAL(gcol, ncol=10, NAME=TRUE, NUM=TRUE) pl = c("grey", "lightblue1", "pink", "darkseagreen2", "gold1", "chartreuse1", "aquamarine", "plum1", "goldenrod", "maroon1", "deepskyblue", "palegreen2", "salmon") SHOWPAL(pl, NAME=TRUE, NUM=TRUE) SYSCOL = pastel.colors(100) SHOWPAL(SYSCOL, ncol=10) SYSCOL = sepia.colors(100) SHOWPAL(SYSCOL, ncol=10) SYSCOL = hcl(h=seq(from=0, to=260, length=100) ) SHOWPAL(SYSCOL, ncol=10)
########## make a large screen for a lot of colors ### dev.new(width=12, height=12) SHOWPAL(colors(), ncol=15, NAME=FALSE) gcol = setXMCOL() SHOWPAL(gcol, ncol=10, NAME=TRUE) #### show index: SHOWPAL(gcol, ncol=10, NAME=TRUE, NUM=TRUE) pl = c("grey", "lightblue1", "pink", "darkseagreen2", "gold1", "chartreuse1", "aquamarine", "plum1", "goldenrod", "maroon1", "deepskyblue", "palegreen2", "salmon") SHOWPAL(pl, NAME=TRUE, NUM=TRUE) SYSCOL = pastel.colors(100) SHOWPAL(SYSCOL, ncol=10) SYSCOL = sepia.colors(100) SHOWPAL(SYSCOL, ncol=10) SYSCOL = hcl(h=seq(from=0, to=260, length=100) ) SHOWPAL(SYSCOL, ncol=10)
MAke a slide show similar to Powerpoint presentations
slideshow(P = c("hi", "there", "sugar pie"), dy = 0.2, EX = 0.1, ht = 3, font = 2, anim = FALSE)
slideshow(P = c("hi", "there", "sugar pie"), dy = 0.2, EX = 0.1, ht = 3, font = 2, anim = FALSE)
P |
vector of character strings to display |
dy |
vertical spacing, percentage |
EX |
horizontal offset, percentage |
ht |
Character expansion, see par |
font |
Font choice, see par |
anim |
logical, Animation, TRUE=means animate the input line-by-line |
The function is meant to be used in presentations when R is running a script and text needs to be displayed to explain the talk. The animation is controlled by clicking on the screen using locator(1) function.
Side effects
Jonathan M. Lees<[email protected]>
Ptext1 = c("New Package: Rquake", "Earthquake Location", "Inverse Theory", "Graphics", "Statistical Analysis" ) slideshow(Ptext1, ht=3, anim=FALSE )
Ptext1 = c("New Package: Rquake", "Earthquake Location", "Inverse Theory", "Graphics", "Statistical Analysis" ) slideshow(Ptext1, ht=3, anim=FALSE )
Plot Text labels with border and background color
textrect(x, y, lab, textcol = "black", col = "white", border = "black", off = 0.06, brd = 0.06, pos = 1, log="" , add=TRUE, ...)
textrect(x, y, lab, textcol = "black", col = "white", border = "black", off = 0.06, brd = 0.06, pos = 1, log="" , add=TRUE, ...)
x |
x-location, user coordinates |
y |
y-location, user coordinates |
lab |
character for label |
textcol |
color for labels |
col |
color for background |
border |
color for border, NA=do not plot |
off |
Offset from point, inches, default=0.06 |
brd |
Border around text, inches, default=0.06 |
pos |
numeric, position=one of (0.0, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5), as in the normal text call with pos=1,2,3,4, however, here I allow half way between points. 0 indicates no offset and label is placed centered on the point. |
log |
character, as in plot |
add |
add to existing plot (FALSE returns plotting rectangles) |
... |
additional parameters from par, used for font, cex, etc... |
textrect plots a label on an existing plot at the location designated. The text is surrounded by a rectangular box with color inside and a border. The box can be placed around the designated point at 9 positions. Positions 1,2,3,4 are the same as text parameter pos. Position 0 is centered, i.e. no offset. Positions, 1.5, 2.5, 3.5, 4.5 are at an angle 45 degrees clockwise from the integer values.
graphical side effects.
Jonathan M. Lees<[email protected]>
thepos = c(0, seq(from=1, to=4.5, by=.5)) lab="the string" x = 1:9 y = 1:9 plot(x,y, asp=1) for(i in 1:length(thepos)) { textrect(x[i], y[i], lab, col=i , border='green' , textcol="gold", off=.06, brd=.06 , pos=thepos[i], font=1, cex=.8 ) } x = runif(10) y = runif(10) lab = floor( 1000*runif(10) ) i=sample(thepos, 10, replace = TRUE) col = sample(rainbow(100) , 10, replace = TRUE) plot(x,y, asp=1) textrect(x, y, lab, pos=i , textcol="black", col=col)
thepos = c(0, seq(from=1, to=4.5, by=.5)) lab="the string" x = 1:9 y = 1:9 plot(x,y, asp=1) for(i in 1:length(thepos)) { textrect(x[i], y[i], lab, col=i , border='green' , textcol="gold", off=.06, brd=.06 , pos=thepos[i], font=1, cex=.8 ) } x = runif(10) y = runif(10) lab = floor( 1000*runif(10) ) i=sample(thepos, 10, replace = TRUE) col = sample(rainbow(100) , 10, replace = TRUE) plot(x,y, asp=1) textrect(x, y, lab, pos=i , textcol="black", col=col)
Make a color rectangle (wheel)
VVwheel(BIGMESH = NULL, v = 1)
VVwheel(BIGMESH = NULL, v = 1)
BIGMESH |
color mesh |
v |
v, from hsv color scheme |
M |
meshgrid:
|
ARE |
Radii |
pANG |
angle |
dx |
delta x |
dy |
delta y |
RY |
range x |
RX |
range y |
Jonathan M. Lees<[email protected]>
hsv, VVwheel, wheelrgb
## Not run: BIGMESH = VVwheel( v=1) ## End(Not run)
## Not run: BIGMESH = VVwheel( v=1) ## End(Not run)
Plot a large color rectangle for color selection
wheelrgb(wloc, v, RY)
wheelrgb(wloc, v, RY)
wloc |
output of locator |
v |
v, from hsv color scheme |
RY |
coordinates of meshgrid, output of VVwheel |
vector of colors
Jonathan M. Lees<[email protected]>
colwheel, VVwheel
Function to determine which button of the RPMG was selected during a graphics session.
whichbutt(v, buttons)
whichbutt(v, buttons)
v |
list of x,y coordinates obtained from the locator() function |
buttons |
list of buttons set by the function rowBUTTONS |
whichbutt uses the geometry determined by rowButtons and a list of locator() points to return the buttons clicked on or, if none, 0.
Returns a vector of indexes to buttons selected by the user. Buttons are numebred 1-N so if a click is not on a button, zero is returned.
This function can be used to get interaction with predined buttons and non-button clicks using locator().
Jonathan M. Lees <[email protected]>
rowBUTTONS, locator
################### initial plot plot(c(0,1), c(0,1)) ###### set buttons mybutts = c("DONE", "REFRESH", "rainbow", "topo", "terrain", "CONT", "XSEC","PS" ) colabs = rep(1, length=length(mybutts)) pchlabs = rep(0,length(mybutts)) ###### set button geometry buttons = rowBUTTONS(mybutts, col=colabs, pch=pchlabs) ######## user clicks on plot. When locator finishes, whichbutt ######## determines which buttons were selected and returns the vector L = locator() K = whichbutt(L, buttons) print(K)
################### initial plot plot(c(0,1), c(0,1)) ###### set buttons mybutts = c("DONE", "REFRESH", "rainbow", "topo", "terrain", "CONT", "XSEC","PS" ) colabs = rep(1, length=length(mybutts)) pchlabs = rep(0,length(mybutts)) ###### set button geometry buttons = rowBUTTONS(mybutts, col=colabs, pch=pchlabs) ######## user clicks on plot. When locator finishes, whichbutt ######## determines which buttons were selected and returns the vector L = locator() K = whichbutt(L, buttons) print(K)
Create a print out of comments for insertion in computer code. Used for separating important blocks of code with helpful, easy to find comments.
writeCOMMENT(temp, space = " ", letspace = "", MSUB = "0", prefix = "", suffix = "")
writeCOMMENT(temp, space = " ", letspace = "", MSUB = "0", prefix = "", suffix = "")
temp |
text string |
space |
space between words |
letspace |
space between letters |
MSUB |
text, substitute character, if this is "ALL", then each letter is substituted. default=NULL |
prefix |
prefix before the letters |
suffix |
suffix after the letters |
This is a function used for creating comments in computer code. Letters are a fixed height of 7 lines
List |
26 letters |
Code dumps to the screen, then you must paste in code. If sent in an email, spaces are not preserved. The letters are stored in the routine, these can be changed, but the constant (7 lines) common height should be preserved. Each letter should be one block.
Jonathan M. Lees<[email protected]>
writeCOMMENT("GO TARHEELS", space=" ", letspace = "", MSUB="ALL", prefix="/*" , suffix="*/" ) writeCOMMENT("START", space=" ", letspace = "", MSUB="ALL", prefix="#######" ) writeCOMMENT("J M lees", space=" ", letspace = "", MSUB="0" ) writeCOMMENT("J. M. Lees", space=" ", letspace = "", MSUB="0" ) writeCOMMENT("J. M. Lees", space=" ", letspace = "", MSUB="." ) writeCOMMENT("J. M. Lees", space=" ", letspace = "" ) writeCOMMENT("J. M. Lees", space="---------", letspace = "" ) writeCOMMENT("J. M. Lees", space=" ", letspace = "", MSUB="ALL" ) writeCOMMENT("J_M_Lees", space=" ", letspace = "", MSUB="ALL" ) writeCOMMENT("abcdefghi") writeCOMMENT("jklmnop") writeCOMMENT("qrstuvwxyz") writeCOMMENT("1234567890") writeCOMMENT("WHY?!.-+=_") writeCOMMENT("2+2=4") writeCOMMENT("e*exp(pi*i)=-1")
writeCOMMENT("GO TARHEELS", space=" ", letspace = "", MSUB="ALL", prefix="/*" , suffix="*/" ) writeCOMMENT("START", space=" ", letspace = "", MSUB="ALL", prefix="#######" ) writeCOMMENT("J M lees", space=" ", letspace = "", MSUB="0" ) writeCOMMENT("J. M. Lees", space=" ", letspace = "", MSUB="0" ) writeCOMMENT("J. M. Lees", space=" ", letspace = "", MSUB="." ) writeCOMMENT("J. M. Lees", space=" ", letspace = "" ) writeCOMMENT("J. M. Lees", space="---------", letspace = "" ) writeCOMMENT("J. M. Lees", space=" ", letspace = "", MSUB="ALL" ) writeCOMMENT("J_M_Lees", space=" ", letspace = "", MSUB="ALL" ) writeCOMMENT("abcdefghi") writeCOMMENT("jklmnop") writeCOMMENT("qrstuvwxyz") writeCOMMENT("1234567890") writeCOMMENT("WHY?!.-+=_") writeCOMMENT("2+2=4") writeCOMMENT("e*exp(pi*i)=-1")
Calculate an expanded bounding region based on a percent of the existing boundaries
XPAND(g, pct = 0.1)
XPAND(g, pct = 0.1)
g |
vector of values |
pct |
fractional percent to expand |
uses the range of the exising vector to estimate the expanded bound
vector, new range
Jonathan M. Lees<[email protected]>
i = 5:10 exi = XPAND(i, pct = 0.1) range(i) range(exi)
i = 5:10 exi = XPAND(i, pct = 0.1) range(i) range(exi)
This function Takes a Digital Elevation Map (or any surface) and illustrates how to take interactive cross sections with RPMG through the surface.
XSECDEM(Data, labs, demo=FALSE)
XSECDEM(Data, labs, demo=FALSE)
Data |
Structure with x, y, z components, typical of contoured surfaces or digital images |
labs |
Vector of labels for Buttons used in the RPMG |
demo |
Argument used to turn off interactive part. Default is FALSE, but for package construction is set to TRUE so no interaction is required. |
XSECDEM is an example stub illustrating the use of RPMG. The idea is to set up a while() loop that uses input from the locator() function to execute or analyze data depending on user defined buttons. Actions are executed when the button clicked matches the list of names provided by the user.
No return values
This code is designed as an example of how to set up a Really Poor Man's GUI. The demo argument is supplied so that this code will run without user input, as when creating a checks for package construction.
Jonathan M. Lees <[email protected]>
whichbutt, rowBUTTONS
data(volcano) attr(volcano, 'dx') =10 attr(volcano, 'dy') =10 mybutts = c("DONE", "REFRESH", "rainbow", "topo", "terrain", "CONT", "XSEC","PS" ) ### in the following change demo=FALSE to get interactive behavior XSECDEM(volcano, mybutts, demo=TRUE)
data(volcano) attr(volcano, 'dx') =10 attr(volcano, 'dy') =10 mybutts = c("DONE", "REFRESH", "rainbow", "topo", "terrain", "CONT", "XSEC","PS" ) ### in the following change demo=FALSE to get interactive behavior XSECDEM(volcano, mybutts, demo=TRUE)
Given ix, iy, iz index get I.
xyztoi(ix, iy,iz,nx, ny, nz)
xyztoi(ix, iy,iz,nx, ny, nz)
ix |
index to col vector |
iy |
index to row vector |
iz |
index to (depth) layer vector |
nx |
number of blocks in x axis |
ny |
number of blocks in y axis |
nz |
number of blocks in z axis (layers) |
i |
Index of matrix |
Jonathan M. Lees<jonathan.lees.edu>
itoxyz
k = itoxyz(24, 6, 6, 1) xyztoi(k$ix, k$iy, k$iz, 6, 6, 1) nx = 20 ny = 20 nz = 40 k = itoxyz(2440, nx, ny, nz) xyztoi(k$ix, k$iy, k$iz, nx, ny, nz )
k = itoxyz(24, 6, 6, 1) xyztoi(k$ix, k$iy, k$iz, 6, 6, 1) nx = 20 ny = 20 nz = 40 k = itoxyz(2440, nx, ny, nz) xyztoi(k$ix, k$iy, k$iz, nx, ny, nz )
Get information on Y-margin for plotting
ymarginfo(SIDE = 1, s1 = 0.1, s2 = 0.8)
ymarginfo(SIDE = 1, s1 = 0.1, s2 = 0.8)
SIDE |
plotting side 1,2,3,4 |
s1 |
lower percent of margin to return |
s2 |
upper percent of margin to return |
Function uses par to help determine how to plot objects in the margins.
vector c(a, b) giving coordinates in margin worth plotting.
Jonathan M. Lees<jonathan.lees.edu>
par
plot(c(0,1), c(0,1), type='n') s1=0.4 s2=0.95 ym = ymarginfo(SIDE=1, s1=s1, s2=s2)
plot(c(0,1), c(0,1), type='n') s1=0.4 s2=0.95 ym = ymarginfo(SIDE=1, s1=s1, s2=s2)