Skip to content

correlation plot in color

12 messages · Salvador SANCHEZ COLON, Manuel Esteban Lucas Borja, Mollie Brooks +1 more

#
Hi Manuel,


I am glad that you managed to plot the correlation plots. Then, as for the colour argument, bg is the argument for setting the background color, not the symbols color; the argument controlling the symbols colour in plots is color. The error you get seems to be due to the fact that your command is missing? a square bracket at the end.?


Still, I have never used the PerformanceAnalytics package before and I just do not know how to make the chart.Correlation function to use the color argument. My guess is that it is not designed to take such argument.


Salvador


Salvador S?NCHEZ-COL?N
An independent consultant
Statistics, GIS, RS?


En Dom, 22 Marzo, 2020 en 16:42, Manuel Esteban Lucas Borja <ManuelEsteban.Lucas at uclm.es> escribi?:
?

Para: Salvador SANCHEZ COLON
Cc: bfalevlist at gmail.com; r-sig-ecology at r-project.org

Thanks Salvador, 
?
It Works properly and I was able to do the correlation plots excluding the categorical variable as you mentioned. In relation to colours I found the following information from other websites: 
?
?
So the argument bg should be used for adding colours to the correlation plot. 
?
bg= c(?red?, ?green3?,?blue?)[codes(iris$Species)
?
I tried this with my dataset: 
?
chart.Correlation(Libro[,1:4], histogram = T, pch = 19, bg= c(?red?, ?green3?,? ?black??????????????????????????????????????????????????????????? ?blue?)[codes(Libro$Treat))
?
Results:
?
Error: unexpected input in "chart.Correlation(u[,1:4], histogram = T, pch = 19, bg= c(?"
?
Error: unexpected input in "?????????????????????????????????????????????????????????? ?"
?
?
Thanks a lot for your time!
Best
Manuel 
?
?


De: Salvador SANCHEZ COLON <salvadorsanchezcolon at prodigy.net.mx> 
Enviado el: domingo, 22 de marzo de 2020 19:25
Para: Manuel Esteban Lucas Borja <ManuelEsteban.Lucas at uclm.es>
CC: bfalevlist at gmail.com; r-sig-ecology at r-project.org
Asunto: Re: [R-sig-eco] correlation plot in color
?
Hola Manuel:
?
As you have loaded the ggplot2 package, one simple way to do the correlation plots (one at the time though) is, for example for your pair of variables EMF and your first MSD axis:
?ggplot(data = Libro) + ??geom_point(mapping = aes(x = EMF, y = MSD1, color = Treat)) 
I hope this helps.?

?

Salvador

An independent consultant

Biostatistics, GIS, RS
En Dom, 22 Marzo, 2020 en 10:34, Manuel Esteban Lucas Borja <ManuelEsteban.Lucas at uclm.es<mailto:ManuelEsteban.Lucas at uclm.es>> escribi?:

?


Para: Bede-Fazekas ?kos; r-sig-ecology at r-project.org<mailto:r-sig-ecology at r-project.org>
Dear ?kos Bede-Fazekas
Sorry for the missed information. Please see the packages I used: 

library(readxl)
library(dplyr)
library(ggplot2)
library(GGally)
library(Hmisc)
library(corrplot)
library(PerformanceAnalytics)

Then I import the attached dataset (Libro1) containing 5 variables: EMF, bio, MSD1, MSD2 (all of them numerical) and Treat (categorical).
Then I wrote:

            
And got the error: 

Error in pairs.default(x, gap = 0, lower.panel = panel.smooth, upper.panel = panel.cor) : 
non-numeric argument to 'pairs' 

And I would like to obtain the plot you can see on the doc file, where correlation points are divided by a category (red, gren and blue)

Thanks a lot for your help
Manuel 



-----Mensaje original-----
De: R-sig-ecology <r-sig-ecology-bounces at r-project.org<mailto:r-sig-ecology-bounces at r-project.org>> En nombre de Bede-Fazekas ?kos
Enviado el: domingo, 22 de marzo de 2020 16:57
Para: r-sig-ecology at r-project.org<mailto:r-sig-ecology at r-project.org>
Asunto: Re: [R-sig-eco] correlation plot in color

Dear Manuel,

since neither a reproducible example or your dataset are provided, nor the details of your problem (results of sessionInfo(); the package of corrMatOrder(); the error message you got) are known by us, it is a bit hard to help you. Anyway, I guess, that your data is not in categorical
(factor) but in ordinal (ordered) scale. If you convert your ordoered data to numeric with as.numeric(), then Spearman and Kendall rank correlations can be used.

HTH,
?kos Bede-Fazekas
Hungarian Academy of Sciences


2020.03.22. 14:29 keltez?ssel, Manuel Esteban Lucas Borja ?rta:
_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org<mailto:R-sig-ecology at r-project.org>
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org<mailto:R-sig-ecology at r-project.org> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
#
Dear Manuel,

please try this:
palette <- setNames(object = c(?red?, ?green3?, ?black?, ?blue?), nm = 
levels(Libro$Treat))
chart.Correlation(Libro[,1:4], histogram = T, pch = 19, bg= 
palette[Libro$Treat])

Have a nice week,
?kos

2020.03.23. 2:40 keltez?ssel, Salvador SANCHEZ COLON ?rta:

  
  
#
Thanks Bede-Fazekas ?kos, 
Thanks a lot for your help. 

I have installed also the library (colorspace)
I got the following error:
Error: unexpected input in "palette <- setNames(object = c(?"

What can I do?
Best
Manuel 

 
-----Mensaje original-----
De: R-sig-ecology <r-sig-ecology-bounces at r-project.org> En nombre de Bede-Fazekas ?kos
Enviado el: lunes, 23 de marzo de 2020 6:52
Para: r-sig-ecology at r-project.org
Asunto: Re: [R-sig-eco] correlation plot in color

Dear Manuel,

please try this:
palette <- setNames(object = c(?red?, ?green3?, ?black?, ?blue?), nm =
levels(Libro$Treat))
chart.Correlation(Libro[,1:4], histogram = T, pch = 19, bg=
palette[Libro$Treat])

Have a nice week,
?kos

2020.03.23. 2:40 keltez?ssel, Salvador SANCHEZ COLON ?rta:
_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
#
Dear Bede-Fazekas, 

I changed " by ' as I wrote below and nothing happens. No error back but the plot in not in colours.
Best
Manuel 



-----Mensaje original-----
De: R-sig-ecology <r-sig-ecology-bounces at r-project.org> En nombre de Bede-Fazekas ?kos
Enviado el: lunes, 23 de marzo de 2020 6:52
Para: r-sig-ecology at r-project.org
Asunto: Re: [R-sig-eco] correlation plot in color

Dear Manuel,

please try this:
palette <- setNames(object = c(?red?, ?green3?, ?black?, ?blue?), nm =
levels(Libro$Treat))
chart.Correlation(Libro[,1:4], histogram = T, pch = 19, bg=
palette[Libro$Treat])

Have a nice week,
?kos

2020.03.23. 2:40 keltez?ssel, Salvador SANCHEZ COLON ?rta:
_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
#
Thanks Salvador,
Let see if I am able to fix it with the help of specialist
Best
Manuel

Por favor, no imprima este documento si no es estrictamente necesario. Cuidar el medioambiente es responsabilidad de todos.
Este mensaje de correo electr?nico puede contener informaci?n confidencial de la UCLM, siendo para uso exclusivo del destinatario.
Si usted lo ha recibido por error y no es el destinatario del mensaje, le rogamos que no difunda su contenido y lo comunique al remitente.

Please do not print this document unless absolutely necessary. Environmental protection is in our hands.
This e-mail may contain confidential information of the UCLM and is exclusively intended for the addressee.
If you have received it by mistake and are not the intended recipient, do not send the contents and please notify the sender.

De: Salvador SANCHEZ COLON <salvadorsanchezcolon at prodigy.net.mx>
Enviado el: lunes, 23 de marzo de 2020 2:41
Para: Manuel Esteban Lucas Borja <ManuelEsteban.Lucas at uclm.es>
CC: bfalevlist at gmail.com; r-sig-ecology at r-project.org
Asunto: RE: [R-sig-eco] correlation plot in color


Hi Manuel,



I am glad that you managed to plot the correlation plots. Then, as for the colour argument, bg is the argument for setting the background color, not the symbols color; the argument controlling the symbols colour in plots is color. The error you get seems to be due to the fact that your command is missing  a square bracket at the end.



Still, I have never used the PerformanceAnalytics package before and I just do not know how to make the chart.Correlation function to use the color argument. My guess is that it is not designed to take such argument.



Salvador



Salvador S?NCHEZ-COL?N

An independent consultant

Statistics, GIS, RS

En Dom, 22 Marzo, 2020 en 16:42, Manuel Esteban Lucas Borja <ManuelEsteban.Lucas at uclm.es<mailto:ManuelEsteban.Lucas at uclm.es>> escribi?:

Para: Salvador SANCHEZ COLON
Cc: bfalevlist at gmail.com<mailto:bfalevlist at gmail.com>; r-sig-ecology at r-project.org<mailto:r-sig-ecology at r-project.org>
Thanks Salvador,

It Works properly and I was able to do the correlation plots excluding the categorical variable as you mentioned. In relation to colours I found the following information from other websites:
So the argument bg should be used for adding colours to the correlation plot.

bg= c(?red?, ?green3?,?blue?)[codes(iris$Species)

I tried this with my dataset:

chart.Correlation(Libro[,1:4], histogram = T, pch = 19, bg= c(?red?, ?green3?,  ?black?                                                           ?blue?)[codes(Libro$Treat))

Results:

Error: unexpected input in "chart.Correlation(u[,1:4], histogram = T, pch = 19, bg= c(?"
Error: unexpected input in "                                                           ?"


Thanks a lot for your time!
Best
Manuel


De: Salvador SANCHEZ COLON <salvadorsanchezcolon at prodigy.net.mx<mailto:salvadorsanchezcolon at prodigy.net.mx>>
Enviado el: domingo, 22 de marzo de 2020 19:25
Para: Manuel Esteban Lucas Borja <ManuelEsteban.Lucas at uclm.es<mailto:ManuelEsteban.Lucas at uclm.es>>
CC: bfalevlist at gmail.com<mailto:bfalevlist at gmail.com>; r-sig-ecology at r-project.org<mailto:r-sig-ecology at r-project.org>
Asunto: Re: [R-sig-eco] correlation plot in color


Hola Manuel:



As you have loaded the ggplot2 package, one simple way to do the correlation plots (one at the time though) is, for example for your pair of variables EMF and your first MSD axis:



ggplot(data = Libro) +

  geom_point(mapping = aes(x = EMF, y = MSD1, color = Treat))
I hope this helps.

Salvador
An independent consultant
Biostatistics, GIS, RS
En Dom, 22 Marzo, 2020 en 10:34, Manuel Esteban Lucas Borja <ManuelEsteban.Lucas at uclm.es<mailto:ManuelEsteban.Lucas at uclm.es>> escribi?:

Para: Bede-Fazekas ?kos; r-sig-ecology at r-project.org<mailto:r-sig-ecology at r-project.org>
Dear ?kos Bede-Fazekas
Sorry for the missed information. Please see the packages I used:

library(readxl)
library(dplyr)
library(ggplot2)
library(GGally)
library(Hmisc)
library(corrplot)
library(PerformanceAnalytics)

Then I import the attached dataset (Libro1) containing 5 variables: EMF, bio, MSD1, MSD2 (all of them numerical) and Treat (categorical).
Then I wrote:

            
And got the error:

Error in pairs.default(x, gap = 0, lower.panel = panel.smooth, upper.panel = panel.cor) :
non-numeric argument to 'pairs'

And I would like to obtain the plot you can see on the doc file, where correlation points are divided by a category (red, gren and blue)

Thanks a lot for your help
Manuel



-----Mensaje original-----
De: R-sig-ecology <r-sig-ecology-bounces at r-project.org<mailto:r-sig-ecology-bounces at r-project.org>> En nombre de Bede-Fazekas ?kos
Enviado el: domingo, 22 de marzo de 2020 16:57
Para: r-sig-ecology at r-project.org<mailto:r-sig-ecology at r-project.org>
Asunto: Re: [R-sig-eco] correlation plot in color

Dear Manuel,

since neither a reproducible example or your dataset are provided, nor the details of your problem (results of sessionInfo(); the package of corrMatOrder(); the error message you got) are known by us, it is a bit hard to help you. Anyway, I guess, that your data is not in categorical
(factor) but in ordinal (ordered) scale. If you convert your ordoered data to numeric with as.numeric(), then Spearman and Kendall rank correlations can be used.

HTH,
?kos Bede-Fazekas
Hungarian Academy of Sciences


2020.03.22. 14:29 keltez?ssel, Manuel Esteban Lucas Borja ?rta:
_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org<mailto:R-sig-ecology at r-project.org>
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org<mailto:R-sig-ecology at r-project.org> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
#
It looks like the quotes are the fancy type (I can?t remember the official word for that). Try deleting and retyping all the quotes in that command.

cheers,
Mollie
#
Thanks Mollie, 

I have retyped all commands but nothing happens at the end. No error backs and no colour in correlations plots.
Best
Manuel 

 


-----Mensaje original-----
De: Mollie Brooks <mollieebrooks at gmail.com> 
Enviado el: lunes, 23 de marzo de 2020 11:04
Para: Manuel Esteban Lucas Borja <ManuelEsteban.Lucas at uclm.es>
CC: Bede-Fazekas ?kos <bfalevlist at gmail.com>; r-sig-ecology at r-project.org
Asunto: Re: [R-sig-eco] correlation plot in color

It looks like the quotes are the fancy type (I can?t remember the official word for that). Try deleting and retyping all the quotes in that command.

cheers,
Mollie
#
Dear Manuel,

are you sure that Libro1$Treat is really a categorical column (instead 
of character)?
The example code that you sent us works for categorical data:
is.factor(get(data(iris))$Species)
TRUE
If is.factor(Libro1$Treat) is FALSE, then you should convert it from 
character to factor, before creating the color palette and calling 
chart.Correlation():
Libro1$Treat <- as.factor(Libro1$Treat)

Have a nice week,
?kos

2020.03.23. 11:19 keltez?ssel, Manuel Esteban Lucas Borja ?rta:
#
Thanks ?kos, 

I did as you mentioned:
[1] FALSE
But nothing happens. I got again the correlation plot but doc values are not in colour following the Treat classification

Thanks for your time. 
Best
Manuel 


 

-----Mensaje original-----
De: R-sig-ecology <r-sig-ecology-bounces at r-project.org> En nombre de Bede-Fazekas ?kos
Enviado el: lunes, 23 de marzo de 2020 14:54
Para: r-sig-ecology at r-project.org
Asunto: Re: [R-sig-eco] correlation plot in color

Dear Manuel,

are you sure that Libro1$Treat is really a categorical column (instead of character)?
The example code that you sent us works for categorical data:
is.factor(get(data(iris))$Species)
TRUE
If is.factor(Libro1$Treat) is FALSE, then you should convert it from character to factor, before creating the color palette and calling
chart.Correlation():
Libro1$Treat <- as.factor(Libro1$Treat)

Have a nice week,
?kos

2020.03.23. 11:19 keltez?ssel, Manuel Esteban Lucas Borja ?rta:
_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
#
Dear Manuel,
and what happens if you use pairs() instead of chart.Correlation()? Is 
it colored? If yes, then it is a possible bug in function 
chart.Correlation().
Best,
?kos

2020.03.23. 17:20 keltez?ssel, Manuel Esteban Lucas Borja ?rta:
#
Dear ?kos, 
Thanks for your priceless time and help. Still not working.
Warning messages:

1: In doTryCatch(return(expr), name, parentenv, handler) :
  "histogram" is not a graphical parameter
2: In doTryCatch(return(expr), name, parentenv, handler) :
  "histogram" is not a graphical parameter
There were 50 or more warnings (use warnings() to see the first 50)

And no colours on the correlation plots

 Best





-----Mensaje original-----
De: R-sig-ecology <r-sig-ecology-bounces at r-project.org> En nombre de Bede-Fazekas ?kos
Enviado el: lunes, 23 de marzo de 2020 18:46
Para: r-sig-ecology at r-project.org
Asunto: Re: [R-sig-eco] correlation plot in color

Dear Manuel,
and what happens if you use pairs() instead of chart.Correlation()? Is it colored? If yes, then it is a possible bug in function chart.Correlation().
Best,
?kos

2020.03.23. 17:20 keltez?ssel, Manuel Esteban Lucas Borja ?rta:
_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
#
Dear Manuel,
the warning is saying that pairs() should be called without the 
histogram parameter. But the problem of black point symbols is caused by 
another thing: you chose a pch that has only color (col) but has no 
background/filling color (bg). Let's choose a pch value from the 21:25 
interval and both pairs() and chart.Correlation() will plot symbols 
filled with colors!
Best,
?kos

2020.03.23. 19:09 keltez?ssel, Manuel Esteban Lucas Borja ?rta: