drawLabels | R Documentation |
Draw text labels on a base R plot
drawLabels(
txt = NULL,
newCoords = NULL,
x = NULL,
y = NULL,
lx = NULL,
ly = NULL,
segmentLwd = 1,
segmentCol = "#00000088",
drawSegments = TRUE,
boxBorderColor = "#000000AA",
boxColor = "#FFEECC",
boxLwd = 1,
drawBox = TRUE,
drawLabels = TRUE,
font = 1,
labelCex = 0.8,
boxCexAdjust = 1.9,
labelCol = alpha2col(alpha = 0.8, setTextContrastColor(boxColor)),
doPlot = TRUE,
xpd = NA,
preset = "default",
adjPreset = "default",
preset_type = "plot",
adjX = 0.5,
adjY = 0.5,
panelWidth = "default",
trimReturns = TRUE,
text_fn = getOption("jam.text_fn", graphics::text),
verbose = FALSE,
...
)
txt |
|
newCoords |
|
x , y |
|
lx , ly |
|
segmentLwd , segmentCol |
|
drawSegments |
|
boxBorderColor |
|
boxColor |
|
boxLwd |
|
drawBox |
|
drawLabels |
|
font |
|
labelCex |
|
boxCexAdjust |
|
labelCol |
|
doPlot |
|
xpd |
|
preset |
|
preset_type , adjPreset |
|
adjX , adjY |
|
panelWidth |
|
trimReturns |
|
text_fn |
|
verbose |
|
... |
additional arguments are passed to |
This function takes a vector of coordinates and text labels, and draws the labels with colored rectangles around each label on the plot. Each label can have unique font, cex, and color, and are drawn using vectorized operations.
To enable shadow text include argument: text_fn=jamba::shadowText
TODO: In future allow rotated text labels. Not that useful within a plot panel, but sometimes useful when draw outside a plot, for example axis labels.
invisible data.frame containing label coordinates used
to draw labels. This data.frame can be manipulated and provided
as input to drawLabels()
for subsequent customized label
positioning.
Other jam plot functions:
adjustAxisLabelMargins()
,
coordPresets()
,
decideMfrow()
,
getPlotAspect()
,
groupedAxis()
,
imageByColors()
,
imageDefault()
,
minorLogTicksAxis()
,
nullPlot()
,
plotPolygonDensity()
,
plotRidges()
,
plotSmoothScatter()
,
shadowText()
,
shadowText_options()
,
showColors()
,
sqrtAxis()
,
usrBox()
nullPlot(plotAreaTitle="");
dl_topleft <- drawLabels(x=graphics::par("usr")[1],
y=graphics::par("usr")[4],
txt="Top-left\nof plot",
preset="topleft",
boxColor="blue4");
drawLabels(x=graphics::par("usr")[2],
y=graphics::par("usr")[3],
txt="Bottom-right\nof plot",
preset="bottomright",
boxColor="green4");
drawLabels(x=mean(graphics::par("usr")[1:2]),
y=mean(graphics::par("usr")[3:4]),
txt="Center\nof plot",
preset="center",
boxColor="purple3");
graphics::points(x=c(graphics::par("usr")[1], graphics::par("usr")[2],
mean(graphics::par("usr")[1:2])),
y=c(graphics::par("usr")[4], graphics::par("usr")[3],
mean(graphics::par("usr")[3:4])),
pch=20,
col="red",
xpd=NA);
nullPlot(plotAreaTitle="");
graphics::title(main="place label across the full top plot panel", line=2.5)
dl_top <- drawLabels(
txt=c("preset='topright', adjPreset='topright', \npanelWidth='force'",
"preset='topright',\nadjPreset='bottomleft'",
"preset='bottomleft', adjPreset='topright',\npanelWidth='force'"),
preset=c("topright", "topright", "bottomleft"),
adjPreset=c("topleft", "bottomleft", "topright"),
panelWidth=c("force", "none", "force"),
boxColor=c("red4",
"blue4",
"purple3"));
graphics::box(lwd=2);
opar <- graphics::par("mfrow"=c(1, 3), "xpd"=TRUE);
on.exit(graphics::par(opar));
isub <- c(force="Always full panel width",
minimum="At least full panel width or larger",
maximum="No larger than panel width");
for (i in c("force", "minimum", "maximum")) {
nullPlot(plotAreaTitle="", doMargins=FALSE);
graphics::title(main=paste0("panelWidth='", i, "'\n",
isub[i]));
drawLabels(labelCex=1.2,
txt=c("Super-wide title across the top\npanelWidth='force'",
"bottom label"),
preset=c("top", "bottom"),
panelWidth=i,
boxColor="red4")
}
graphics::par("mfrow"=c(1, 1));
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.