[R] Use of different colours in plot

Stefano Sofia stefano.sofia at regione.marche.it
Fri Jul 18 10:45:14 CEST 2014


Thank you Jim, perfect.
________________________________________
Da: Jim Lemon [jim at bitwrit.com.au]
Inviato: venerdì 18 luglio 2014 10.22
A: r-help at r-project.org
Cc: Stefano Sofia
Oggetto: Re: [R] Use of different colours in plot

On Fri, 18 Jul 2014 07:07:04 AM Stefano Sofia wrote:
> Dear R list users,
> I have a data frame called catchment like
>
> "year" "season" "rainfall" "colour"
> 1953 1 409.5 "black"
> 1953 2 145.3 "black"
> 1953 3 285.6 "red"
> 1953 4 275.0 "black"
> 1954 1 273.8 "black"
> 1954 2 342.8 "blue"
> 1954 3 167.6 "black"
> 1954 4 341.1 "black"
> 1955 1 182.3 "blue"
> 1955 2 211.8 "black"
> 1955 3 222.6 "black"
> 1955 4 522.1 "black"
> 1956 1 248.7 "red"
> 1956 2 244.9 "black"
> ...
>
> and I would like to plot it with the colours specified in the column
colour
> (at the moment the colours are three: black, red and blue. I would
like to
> have the possibility to add oher colours to this list).
 With
>
> plot(catchment$year, catchment$rainfall, main="River Aso",
xlab="years",
> ylab="mm", type="p", col=catchment$colour)

> the colours displayed in the graph are not the ones I have chosen.
> I looked for the answer, which probably involves a transformation to
factor,
> but I am not able to understand well the solution.
 Could somebody help me?
>
> Thank you
> Stefano Sofia
>
Hi Stefano,
Try this:

plot(catchment$year, catchment$rainfall,
 main="River Aso", xlab="years",
 ylab="mm", type="p",
 col=as.character(catchment$colour))

Jim


________________________________

AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere informazioni confidenziali, pertanto è destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si è il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed urgenza, la risposta al presente messaggio di posta elettronica può essere visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system.


More information about the R-help mailing list