[R] Use of different colours in plot
Jim Lemon
jim at bitwrit.com.au
Fri Jul 18 10:22:01 CEST 2014
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
More information about the R-help
mailing list