as.Date and Legend in a plot

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

as.Date and Legend in a plot

Ogbos
Dear Contributors,

I am surprised that I cannot add legend to a certain plot. Although the
x-axis indicates years, the actual data was in year, month and day format.
I then used as.Date to play around and get what I am looking for. I am,
however, worried that I cannot add legend to the plot no matter how I
tried. Looking at the axis, I tried:
legend(1998,3, c("Climax", "Thule", "Sopo"), lty = 1, col =
c("black","red","blue")). I also tried:

legend(as.Date(1998-02-10),3, c("Climax", "Thule", "Sopo"), lty = 1, col =
c("black","red","blue"))
but no result and no error.

I have attached the plot in case it will assist in your suggestions.

Many thanks for your time.

Ogbos
______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: as.Date and Legend in a plot

David Winsemius

> On Jun 22, 2018, at 12:12 PM, Ogbos Okike <[hidden email]> wrote:
>
> Dear Contributors,
>
> I am surprised that I cannot add legend to a certain plot. Although the
> x-axis indicates years, the actual data was in year, month and day format.
> I then used as.Date to play around and get what I am looking for. I am,
> however, worried that I cannot add legend to the plot no matter how I
> tried. Looking at the axis, I tried:
> legend(1998,3, c("Climax", "Thule", "Sopo"), lty = 1, col =
> c("black","red","blue")). I also tried:
>
> legend(as.Date(1998-02-10),

I don't think you understand the difference between character values and numeric values. Thr using

as.Date("1998-02-10")


> 3, c("Climax", "Thule", "Sopo"), lty = 1, col =
> c("black","red","blue"))
> but no result and no error.
>
> I have attached the plot in case it will assist in your suggestions.
>
> Many thanks for your time.
>
> Ogbos
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: as.Date and Legend in a plot

R help mailing list-2
In reply to this post by Ogbos
What David Winsemius said, plus:

Does
  legend('topleft', c("Climax", "Thule", "Sopo"), lty = 1, col = ("black","red","blue"))
not work?

It should, which will illustrate that you CAN add a legend to the plot.

The x,y that you supply to legend must be values that are within the x,y range of the plot. Type
   par()$usr
to see what that range is, and I think you will see that 1998 is not within the plot range.

David showed you how to supply legend with an x value that is, we assume, within the plot range.

You *should* have had an error on your second try:

> as.Date(1998-02-10)
Error in as.Date.numeric(1998 - 2 - 10) : 'origin' must be supplied

-Don

--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
 
 

´╗┐On 6/22/18, 12:12 PM, "R-help on behalf of Ogbos Okike" <[hidden email] on behalf of [hidden email]> wrote:

    Dear Contributors,
   
    I am surprised that I cannot add legend to a certain plot. Although the
    x-axis indicates years, the actual data was in year, month and day format.
    I then used as.Date to play around and get what I am looking for. I am,
    however, worried that I cannot add legend to the plot no matter how I
    tried. Looking at the axis, I tried:
    legend(1998,3, c("Climax", "Thule", "Sopo"), lty = 1, col =
    c("black","red","blue")). I also tried:
   
    legend(as.Date(1998-02-10),3, c("Climax", "Thule", "Sopo"), lty = 1, col =
    c("black","red","blue"))
    but no result and no error.
   
    I have attached the plot in case it will assist in your suggestions.
   
    Many thanks for your time.
   
    Ogbos
    ______________________________________________
    [hidden email] mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
    and provide commented, minimal, self-contained, reproducible code.
   

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.