barplot2D | R Documentation |
This function is used by draw.barplot2D
to add a 2-dimensional barplot at a specific location to an existing plot. It can be used directly but in general it is advisable to use draw.barplot2D
instead.
barplot2D(z, x = 0, y = 0, width = 1, height = 1, colour, add = TRUE, col.frame = NULL,
lwd.frame = 1, threshold = 1.1, ...)
z |
vector, containing positive numbers (NAs are discarded), to be used as the area of the rectangles |
colour |
a vector (same length as |
x, y |
the location of the centre of the pie on the x and y-scale of the existing plot. |
width, height |
the width and height of the 2D barplot (user coordinate units). |
add |
logical, should the 2D barplot be added to an existing plot> Defaults to TRUE |
col.frame |
the colour of the frame of the 2D barplot |
lwd.frame |
the line width of the frame of the 2D barplot |
threshold |
the maximum acceptable aspect ratio of the rectangles |
... |
arguments to be passed to |
The algorithm that determines the location of each rectangle within the 2D-barplot is as follows: 1) Start with a rectangle representing the highest value of z
. 2) Try to put the first rectangle on the left. 3) If it too elongated, try to put two rectangles, on top of each other, on the left. 4) When you have placed those rectangles, proceed with the remaining rectangles.
More precisely, we choose the number of rectables to stack so as to minimize the following penalty: penalty for the first rectangle in the stack + penalty for the last where the penalty of a rectangle is: ratio - 1.1
. where ratio
is the ratio of the longer side by the smaller.
Adapted by Hans Gerritsen
This function was adapted from code pulbished on http://zoonek2.free.fr/UNIX/48_R/03.html (accessed 1 Jun 2012).
draw.barplot2D
plot(NA,NA, xlim=c(-1,1), ylim=c(-1,1) )
barplot2D(z=rpois(6,10), x=-0.5, y=0.5, width=0.75, height=0.75, colour=rainbow(6))
barplot2D(z=rpois(4,10), x=0.5, y=-0.5, width=0.5, height=0.5, colour=rainbow(4))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.