plot.JamPolygon | R Documentation |
Plot JamPolygon object
## S3 method for class 'JamPolygon'
plot(
x,
y,
xlim = NULL,
ylim = NULL,
flip_sign = 1,
render_vectorized = FALSE,
render_thin_border = TRUE,
linejoin = c("bevel", "mitre", "round"),
mitrelimit = -20,
show_labels = TRUE,
buffer = 0.05,
do_newpage = TRUE,
do_viewport = TRUE,
do_pop_viewport = TRUE,
do_draw = TRUE,
do_experimental = TRUE,
verbose = FALSE,
debug = FALSE,
...
)
x |
|
y |
not used. |
xlim , ylim |
|
flip_sign |
|
render_vectorized |
|
render_thin_border |
|
linejoin |
|
mitrelimit |
|
show_labels |
|
buffer |
|
do_newpage |
|
do_viewport |
|
do_pop_viewport |
|
do_draw |
|
do_experimental |
|
verbose |
|
debug |
|
... |
additional arguments are recognized to customize plot features. |
This function is a general purpose function to plot JamPolygon
objects using grid
graphics.
It currently calls direct rendering functions, for example
grid::grid.path()
, grid::grid.lines()
.
Rendering guidelines used by this function:
Each polygon is rendered in order, and in series.
All polygon labels are rendered afterward, so that labels are not covered by subsequent polygons.
jp@polygons
:name
, label
- name and display label. A label
of NA
or ""
will not be rendered.
label_color
- color used to render each polygon label.
family
, fontsize
- font family, and font point size used to render
each polygon label.
x
, y
- x- and y-coordinates to define each polygon or multipolygon.
fill
- polygon fill color, or NA
for no fill color.
border
, border.lwd
- border color and line width (outer border)
innerborder
, innerborder.lwd
- inner border and line width
Todo:
Enable arguments in ...
to override equivalent values in columns of
jp@polygons
.
Convert grid
rendering to generate graphical objects (grobs)
which can be optionally rendered, or returned as a gTree
.
Continue debugging the vwline
graphical glitches which are
apparent when rendering outer borders.
See https://github.com/pmur002/vwline/issues/2.
Current recommendation is to render outer border after the inner border, and with outer border at least the same or larger width as the inner border. Otherwise, for acute angles, inner border may exceed the outer border because of its line width. However, if the outer border is drawn afterward, it will fully cover the inner border. With sufficiently small inner border width, the graphical glitch may not be apparent.
Consider allowing labels for each multi-part polygon.
Consider drawing optional x- and y-axis, although both could be added
using grid
functions.
JamPolygon
object, invisibly. Some grid
attributes are
added to the returned object:
"adjx"
,"adjy"
: functions to adjust native x/y values to
the corresponding grid
units in "snpc"
.
"viewport"
: the grid::viewport()
object suitable to push
the same viewport in order to add features to an existing plot.
"xrange"
,"yrange"
: x- and y-axis ranges used to determine
the viewport to be used.
"grob_tree"
: a grid::gTree
object suitable to call
grid::grid.draw()
. It includes the same viewport
, so it
does not need to have the viewport defined.
Other JamPolygon:
JamPolygon-class
,
Venndir-class
,
[,JamPolygon,ANY,ANY,ANY-method
,
add_orientation_JamPolygon()
,
area_JamPolygon()
,
bbox_JamPolygon()
,
buffer_JamPolygon()
,
check_JamPolygon()
,
check_Venndir()
,
eulerr_to_JamPolygon()
,
farthest_point_JamPolygon()
,
find_venn_overlaps_JamPolygon()
,
has_point_in_JamPolygon()
,
intersect_JamPolygon()
,
label_fill_JamPolygon()
,
label_outside_JamPolygon()
,
label_segment_JamPolygon()
,
labelr_JamPolygon()
,
minus_JamPolygon()
,
nearest_point_JamPolygon()
,
nudge_JamPolygon()
,
point_in_JamPolygon()
,
polyclip_to_JamPolygon()
,
polygon_circles()
,
polygon_ellipses()
,
sample_JamPolygon()
,
split_JamPolygon()
,
union_JamPolygon()
,
update_JamPolygon()
dfx <- data.frame(name=c("polygon1", "polygon2"),
x=I(list(
list(c(1, 4, 4, 1),
c(2, 3, 3, 2)),
c(5, 6, 6, 5))),
y=I(list(
list(c(1, 1, 4, 4),
c(2, 2, 3, 3)),
c(1, 1, 2, 2))),
fill=c("gold", "firebrick"))
jpx <- new("JamPolygon", polygons=dfx);
plot(jpx);
# if you want to add to the plot, you must capture output
# to use the viewport
jpxout <- plot(jpx);
vp <- attr(jpxout, "viewport");
adjx <- attr(jpxout, "adjx");
adjy <- attr(jpxout, "adjy");
grid::grid.path(x=adjx(c(4, 5, 5, 4) + 0.5),
y=adjy(c(3, 3, 4, 4)),
vp=vp,
gp=grid::gpar(fill="purple", col="red1", lwd=2),
default.units="snpc")
grid::grid.text(x=adjx(5), y=adjy(3.5),
label="new grob",
vp=vp,
gp=grid::gpar(col="yellow", fontsize=20),
default.units="snpc")
dfz <- data.frame(name=c("polygon1", "polygon2", "polygon3"),
x=I(list(
list(c(1, 4, 4, 1),
c(2, 3, 3, 2)),
list(c(4.5, 6.5, 6.5, 4.5),
c(5, 6, 6, 5)),
list(c(1, 4, 4, 1),
c(2, 3, 3, 2),
c(5, 6, 6, 5)))),
y=I(list(
list(c(1, 1, 4, 4),
c(2, 2, 3, 3)),
list(c(1, 1, 3, 3),
c(3, 3, 4, 4)+0.5),
list(c(5, 5, 8, 8),
c(6, 6, 7, 7),
c(6, 6, 7, 7)))),
fill=c("gold", "firebrick", "dodgerblue"));
jpz <- new("JamPolygon", polygons=dfz);
jpz@polygons[, c("label_x", "label_y")] <- as.data.frame(labelr_JamPolygon(jpz))
jpz@polygons$outerborder <- c("orange", "gold", "purple");
jpz@polygons$outerborder.lwd <- 0;
jpz@polygons$outerborder.lwd <- c(3, 4, 5);
jpz@polygons$innerborder <- c("orange4", "gold3", "purple4");
jpz@polygons$innerborder.lwd <- c(3, 4, 5);
jpz@polygons$border.lwd <- 1;
jpz@polygons$border.lty <- 2;
#jpz <- add_orientation_JamPolygon(jpz);
plot(jpz);
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.