[R] Legend placement in barplot?

Dan Bolser dmb at mrc-dunn.cam.ac.uk
Thu Nov 4 14:24:11 CET 2004


On Wed, 3 Nov 2004, Gabor Grothendieck wrote:

>Dan Bolser <dmb <at> mrc-dunn.cam.ac.uk> writes:
>
>: 
>: This has been asked before, but all the answers are hidiously complex.
>: 
>: The
>: 
>: legend.text=TRUE 
>: 
>: option of barplot is almost exactly what I need, except I need a
>: 
>: legend.placement='tl'
>: 
>: (top left) option. This option would be in contrast to the default
>: placement which we could call 'tr' (top right).
>: 
>: Anyone know how to edit the barplot code to make this change? Could
>: someone like me work out how to do this?
>: 
>: Cheers,
>: Dan.
>
>
>Check out gplots::smartlegend (in the R 2.0.0 gregmisc bundle).


This works great, but like the (smart)legend function, fill=true appears
to be giving me only black boxes.

Here is what I add..

smartlegend(x="left",y="top",
            c("PDB","MSD"),
            fill=TRUE,
            col=c("red","blue")
           )

The result is two black boxes! I tried swapping the order of the color and
fill options, but to the same effect.

I got round the problem by using...

smartlegend(x="left",y="top",
            c("PDB","MSD"),
            col=c("red","blue"),
            lwd=5
            )

Not quite the same, but good enough.


One other thing (while I am generally complaining), the legend dosn't
scale correctly as I change the image size with the mouse. All the other
aspects of the barplot scale correctly. If I redraw the legend after
changing the size it is scaled correctly, suggesting that this problem
isn't fundamental, but is a bug in the implementation of legend.



>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list