[R] legend issues.

David Winsemius dwinsemius at comcast.net
Mon Feb 25 18:38:33 CET 2013

On Feb 25, 2013, at 7:37 AM, Nicole Ford wrote:

> hello, all.
> one of my students is having an issue with the pie & legend function.
> this is her code.  (below)
> it works just fine for me.
> her error is "plot.new has not been called yet".  i know this means her pie chart is coming up blank so the legend will not work.

So at that point, why not issue the command:

plot.new()    # ?

Graphics problems can be very system specific. Follow-up should include a proper adherence to the Posting Guide advice about the necessary problem description. You should assist R help by first educating yourself and then giving your students proper training in how to construct questions for R-help.

> according to ?graphics  this package *is* supposed to handle these functionalities.  however, when i tried to install it i get the following error:
> Warning message:
> package Œgraphics‚ is not available (for R version 2.15.2) 

The graphics package is part of the base installation. As far as I know you cannot reinstall it. You would instead need to reinstall R if you thought her installation if R was corrupt.


> however, the ?graphics page shows it is indeed available for this version of R.
> Package:       graphics
> Version:       2.15.2
> Priority:      base
> Title:         The R Graphics Package
> Author:        R Core Team and contributors worldwide
> Maintainer:    R Core Team <R-core at r-project.org>
> Description:   R functions for base graphics
> Imports:       grDevices
> License:       Part of R 2.15.2
> Built:         R 2.15.2; ; 2012-10-26 16:14:39 UTC; unix
> thoughts are greatly appreciated.
>> strength <- factor(c(rep("8.0-9.9", 2), rep("7.0-7.9", 12), rep("6.0-6.9", 108)))
>> plot(strength, xlab="Earthquake Strength", ylab="Frequency")
>> histogram(strength, xlab="Earthquake Strength", ylab="Relative Frequency by Percentage")
>> pie(table(strength))
> legend("topright", title="Earthquake Strength", cex=0.6, pch=16, col=c("white", "blue", "red"), legend=c("6.0 to 6.9", "7.0 to 7.9", "8.0 to 8.9"), ncol=3)

David Winsemius
Alameda, CA, USA

More information about the R-help mailing list