[R] Reverse legend label order in barplot
peter dalgaard
pdalgd at gmail.com
Sun Jul 3 20:52:38 CEST 2011
On Jul 2, 2011, at 02:14 , Marc Schwartz wrote:
>
>
> Alternatively, You can use legend() separately to add the legend to the barplot in the fashion that you desire.
>
> Thus:
>
> barplot(mat)
>
> legend("topright", legend = rownames(mat),
> fill = grey.colors(nrow(mat)))
>
Yup. One thing: I'd future-proof it, making double-damn-sure that it is actually the same colors in the plot and the legend by going
clr <- grey.colors(nrow(mat))
barplot(mat, col = clr)
legend("topright", legend = rownames(mat), fill = clr)
--
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help
mailing list