plot3dHive | R Documentation |
These functions plot a HivePlotData
object in either 2D or 3D,
depending upon which function is called.
plot3dHive(
HPD,
ch = 1,
dr.nodes = TRUE,
method = "abs",
axLabs = NULL,
axLab.pos = NULL,
LA = FALSE,
...
)
plotHive(
HPD,
ch = 1,
method = "abs",
dr.nodes = TRUE,
bkgnd = "black",
axLabs = NULL,
axLab.pos = NULL,
axLab.gpar = NULL,
anNodes = NULL,
anNode.gpar = NULL,
grInfo = NULL,
arrow = NULL,
np = TRUE,
anCoord = "local",
...
)
HPD |
An object of S3 class |
ch |
Numeric; the size of the central hole in the hive plot. |
dr.nodes |
Logical; if |
method |
Character. Passed to |
axLabs |
A vector of character strings for the axis labels. |
axLab.pos |
Numeric; An offset from the end of the axis for label
placement. Either a single value or a vector of values. If a single value,
all labels are offset the same amount. If a vector of values, there should
be a value for each axis. This allows flexibility with long axis names.
The units depend upon the |
LA |
(Applies to |
... |
Additional parameters to be passed downstream. |
bkgnd |
Any valid color specification. Used for the background color
for |
axLab.gpar |
(Applies to |
anNodes |
(Applies to |
anNode.gpar |
(Applies to |
grInfo |
(Applies to |
arrow |
(Applies to |
np |
(Applies to |
anCoord |
(Applies to |
General. plotHive
uses grid
graphics to produce a 2D hive
plot in a style similar to the original concept. For a 2D plot, axis number
1 is vertical except in the case of 2 axes in which case it is to the right.
plot3dHive
produces a 3D hive plot using rgl
graphics.
Functions from either package can be used to make additional modifications
after the hive plot is drawn, either via the ... argument or by
subsequent function calls. See the examples.
Units and Annotations. If you add node labels, arrows or graphic decorations,
the units that you
must specify are those intrinsic to the data itself, modified by your
setting of ch
and method
. These generally cannot be known
precisely ahead of time, so some experimentation will be necessary to polish
the plots. For instance, if you have data with node radii that run from
4-23 then you have an idea of how to position your annotations if using
method = "abs"
. But the same data plotted with method =
"norm"
or method = "rank"
will require that you move your annotation
positions accordingly. In the first case no radius is larger than 23, but
the maximum radius is 1 when the data is normed and when it is ranked, the
maximum value will depend upon which axis has the most nodes on it, and the
number of unique radii values.
Positioning Node Labels and Graphics.
In addition to the nuances just above, there are two ways to specify the
location of node labels and graphic decorations. Polar coordinates are used
in both cases. If annCoord = "local"
then the angle, radius and
offset arguments are relative to the node to be annotated. An angle of 0
positions the label horizontally to the right of the node. Thus the label
can be placed within a circular area around the node. If annCoord =
"global"
then the specifications are relative to dead center on the plot.
These two methods give one lots of flexibility in lining up labels in
different ways. See the examples.
Size of Graphics. The size of
graphic decorations is controlled by the column 'width' in grInfo
.
The ultimate call to display the graphic is done with as.raster
.
Specifying only the width preserves the aspect ratio of the graphic. See
?as.raster
for further discussion.
Colors. For any of the
gpar
arguments, watch out: In grid graphics the default color for
text and arrows is black, so if are using the default bkgnd = "black"
in the hive plot be sure to specify col = "white"
(or some other
non-black color) for the labels and arrows or you won't see them.
Speed and 3D Hive Plots. For most work with plot3dHive
, use LA
= FALSE
for speed of drawing. LA = TRUE
is over 20 times slower,
and is more appropriate for high quality hive plots. These are probably
better made with R CMD BATCH script.R
rather than interactive use.
None. Side effect is a plot.
plot3dHive()
: Create a 3D Hive Plot
plotHive()
: Create a 2D Hive Plot
Bryan A. Hanson, DePauw University. hanson@depauw.edu
### 2D Hive Plots
require("grid")
# Generate some random data
test2 <- ranHiveData(nx = 2)
test3 <- ranHiveData(nx = 3)
# First the nx = 2 case.
# Note that gpar contains parameters that apply to both the
# axis labels and arrow. A 6th value in arrow offsets the arrow vertically:
plotHive(test2,
ch = 5, axLabs = c("axis 1", "axis 2"), rot = c(-90, 90),
axLab.pos = c(20, 20), axLab.gpar = gpar(col = "pink", fontsize = 14, lwd = 2),
arrow = c("radius units", 0, 20, 60, 25, 40)
)
# Now nx = 3:
plotHive(test3) # default plot
# Add axis labels & options to nx = 3 example. Note that rot is not part of gpar
plotHive(test3,
ch = 5, axLabs = c("axis 1", "axis 2", "axis 3"),
axLab.pos = c(10, 15, 15), rot = c(0, 30, -30),
axLab.gpar = gpar(col = "orange", fontsize = 14)
)
# Call up a built-in data set to illustrate some plotting tricks
data(HEC)
require("grid") # for text additions outside of HiveR (grid.text)
plotHive(HEC,
ch = 0.1, bkgnd = "white",
axLabs = c("hair\ncolor", "eye\ncolor"),
axLab.pos = c(1, 1),
axLab.gpar = gpar(fontsize = 14)
)
grid.text("males", x = 0, y = 2.3, default.units = "native")
grid.text("females", x = 0, y = -2.3, default.units = "native")
grid.text("Pairing of Eye Color with Hair Color",
x = 0, y = 4,
default.units = "native", gp = gpar(fontsize = 18)
)
# Add node labels and graphic decorations
# The working directory has to include
# not only the grInfo and anNodes files but also the jpgs.
# So, we are going to move to such a directory and return you home afterwards.
currDir <- getwd()
setwd(system.file("extdata", "Misc", package = "HiveR"))
plotHive(HEC,
ch = 0.1, bkgnd = "white",
axLabs = c("hair\ncolor", "eye\ncolor"),
axLab.pos = c(1, 1),
axLab.gpar = gpar(fontsize = 14),
anNodes = "HECnodes.txt",
anNode.gpar = gpar(col = "black"),
grInfo = "HECgraphics.txt",
arrow = c("more\ncommon", 0.0, 2, 4, 1, -2)
)
grid.text("males", x = 0, y = 2.3, default.units = "native")
grid.text("females", x = 0, y = -2.3, default.units = "native")
grid.text("Pairing of Eye Color with Hair Color",
x = 0, y = 3.75,
default.units = "native", gp = gpar(fontsize = 18)
)
grid.text("A test of plotHive annotation options",
x = 0, y = 3.25,
default.units = "native", gp = gpar(fontsize = 12)
)
grid.text("Images from Wikipedia Commons",
x = 0, y = -3.5,
default.units = "native", gp = gpar(fontsize = 9)
)
setwd(currDir)
# Use the node label concept to create tick marks
currDir <- getwd()
setwd(system.file("extdata", "Misc", package = "HiveR"))
plotHive(HEC,
ch = 0.1, bkgnd = "white",
axLabs = c("hair\ncolor", "eye\ncolor"),
axLab.pos = c(1, 1),
axLab.gpar = gpar(fontsize = 14),
anNodes = "HECticks.txt",
anNode.gpar = gpar(col = "black"),
arrow = c("more\ncommon", 0.0, 2, 4, 1, -2),
dr.nodes = FALSE
)
grid.text("males", x = 0, y = 2.3, default.units = "native")
grid.text("females", x = 0, y = -2.3, default.units = "native")
grid.text("Pairing of Eye Color with Hair Color",
x = 0, y = 3.75,
default.units = "native", gp = gpar(fontsize = 18)
)
grid.text("Adding tick marks to the nodes",
x = 0, y = 3.25,
default.units = "native", gp = gpar(fontsize = 12)
)
setwd(currDir)
### 3D Hive Plots. The following must be run interactively.
## Not run:
require("rgl")
test4 <- ranHiveData(nx = 4, type = "3D")
plot3dHive(test4)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.