[R] add a color band
jim at bitwrit.com.au
Mon Nov 4 11:55:17 CET 2013
On 11/04/2013 08:09 PM, Alaios wrote:
> Hi Jim Lemon,
> thanks for the help, I appreciate this.
> right now my code looks like.
> my major problem now is that the
> a. text in the color bar is squeezed so -50 overlaps with -60 and so on
> b. for some reason the color bar sometimes (the same code is called for
> all the data matrices I have) is misaligned in different positions each time
> Could you please also help me with those two?
For your first question, I would simply extend the color legend vertically:
For the second one, you obviously have different dimensions for the data
matrices. So, let's step through a method for getting the legend
position and size from the plot itself. As I have written a few times
previously, par("usr") gives you the dimensions of the plot in user
units. For the example above, the dimensions were:
x - 0->351
y - 0->200
With a bit of arithmetic, you can work out that the legend positions in
the above are:
# x position of lower left corner of legend
# y position of lower left corner
# x position of upper right corner of legend
# y position of upper right corner
Having these lines means that you can get the position and size of the
legend about right from the information provided by par("usr") even if
you change the number of cells in the matrix passed to color2D.matplot.
Then you would call:
unless of course you wanted to change the values in the scale markings.
I'll leave that for you to work out.
More information about the R-help