Colorizing different individuals with fviz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Colorizing different individuals with fviz

Mahmood Naderan-Tahan
Hi

I use this command to generate a graph of individuals


ind <- get_famd_ind(res.famd)
fviz_famd_ind(res.famd, repel = TRUE)


I would like to know how can I specify different colors for different individuals?

The colorization is not very complex. Basically, I want to specify rows[1:10] to be shown in black and rows[11:20] to be shown in red.


Any idea about that?


Regards,
Mahmood

        [[alternative HTML version deleted]]

______________________________________________
[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: Colorizing different individuals with fviz

Jim Lemon-4
Hi Mahmood,
What you have specified can be done with:

col=c(rep("black",10),rep("red",10))

depending upon what print function you are using. I suspect that this
may be based on a value in your data. For example, if you want  black
for values of some variable up to 10 and red for those over:

col=ifelse(x>10,"red","black)

Jim

On Sun, Mar 28, 2021 at 12:20 AM Mahmood Naderan-Tahan
<[hidden email]> wrote:

>
> Hi
>
> I use this command to generate a graph of individuals
>
>
> ind <- get_famd_ind(res.famd)
> fviz_famd_ind(res.famd, repel = TRUE)
>
>
> I would like to know how can I specify different colors for different individuals?
>
> The colorization is not very complex. Basically, I want to specify rows[1:10] to be shown in black and rows[11:20] to be shown in red.
>
>
> Any idea about that?
>
>
> Regards,
> Mahmood
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [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.
Reply | Threaded
Open this post in threaded view
|

Re: Colorizing different individuals with fviz

PIKAL Petr
In reply to this post by Mahmood Naderan-Tahan
Hi.

You could probably use "col.ind.sup" for this task, however factoextra is
rather rigid in its properties. I still recommend plain prcomp and finetune
biplot with points.
Maybe not so fancy as factoextra but you could format points with shape,
size, colour to characterise some differences.

Cheers
Petr

> -----Original Message-----
> From: R-help <[hidden email]> On Behalf Of Mahmood
> Naderan-Tahan
> Sent: Saturday, March 27, 2021 2:20 PM
> To: [hidden email]
> Subject: [R] Colorizing different individuals with fviz
>
> Hi
>
> I use this command to generate a graph of individuals
>
>
> ind <- get_famd_ind(res.famd)
> fviz_famd_ind(res.famd, repel = TRUE)
>
>
> I would like to know how can I specify different colors for different
> individuals?
>
> The colorization is not very complex. Basically, I want to specify
rows[1:10] to

> be shown in black and rows[11:20] to be shown in red.
>
>
> Any idea about that?
>
>
> Regards,
> Mahmood
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [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.
Reply | Threaded
Open this post in threaded view
|

Re: Colorizing different individuals with fviz

Mahmood Naderan-Tahan
In reply to this post by Jim Lemon-4
Hi Jim,

It seems that the following proposed method doesn't work


ind <- get_famd_ind(res.famd)
fviz_famd_ind(res.famd,
              col=ifelse(x>10,"red","black"),
              repel = TRUE)


Result is:


Error in fviz_famd_ind(res.famd, col = ifelse(x > 10, "red", "black"),  :
  argument 2 matches multiple formal arguments



Any idea to fix that?

Regards,
Mahmood

________________________________
From: Jim Lemon <[hidden email]>
Sent: Saturday, March 27, 2021 9:19:23 PM
To: Mahmood Naderan-Tahan
Cc: [hidden email]
Subject: Re: [R] Colorizing different individuals with fviz

Hi Mahmood,
What you have specified can be done with:

col=c(rep("black",10),rep("red",10))

depending upon what print function you are using. I suspect that this
may be based on a value in your data. For example, if you want  black
for values of some variable up to 10 and red for those over:

col=ifelse(x>10,"red","black)

Jim

On Sun, Mar 28, 2021 at 12:20 AM Mahmood Naderan-Tahan
<[hidden email]> wrote:

>
> Hi
>
> I use this command to generate a graph of individuals
>
>
> ind <- get_famd_ind(res.famd)
> fviz_famd_ind(res.famd, repel = TRUE)
>
>
> I would like to know how can I specify different colors for different individuals?
>
> The colorization is not very complex. Basically, I want to specify rows[1:10] to be shown in black and rows[11:20] to be shown in red.
>
>
> Any idea about that?
>
>
> Regards,
> Mahmood
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [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.

        [[alternative HTML version deleted]]

______________________________________________
[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: Colorizing different individuals with fviz

Bill Dunlap-2
That error means that fviz_famd_ind has more than one argument that
starts with 'col' and you must type a more complete name to
disambiguate it.  Perhaps col.ind=ifelse(...)?

> args(factoextra::fviz_famd_ind)
function (X, axes = c(1, 2), geom = c("point", "text"),
    repel = FALSE, habillage = "none", palette = NULL,
    addEllipses = FALSE, col.ind = "blue", col.ind.sup = "darkblue",
    alpha.ind = 1, shape.ind = 19, col.quali.var = "black",
    select.ind = list(name = NULL, cos2 = NULL, contrib = NULL),
    gradient.cols = NULL, ...)

On Mon, Mar 29, 2021 at 2:20 PM Mahmood Naderan-Tahan
<[hidden email]> wrote:

>
> Hi Jim,
>
> It seems that the following proposed method doesn't work
>
>
> ind <- get_famd_ind(res.famd)
> fviz_famd_ind(res.famd,
>               col=ifelse(x>10,"red","black"),
>               repel = TRUE)
>
>
> Result is:
>
>
> Error in fviz_famd_ind(res.famd, col = ifelse(x > 10, "red", "black"),  :
>   argument 2 matches multiple formal arguments
>
>
>
> Any idea to fix that?
>
> Regards,
> Mahmood
>
> ________________________________
> From: Jim Lemon <[hidden email]>
> Sent: Saturday, March 27, 2021 9:19:23 PM
> To: Mahmood Naderan-Tahan
> Cc: [hidden email]
> Subject: Re: [R] Colorizing different individuals with fviz
>
> Hi Mahmood,
> What you have specified can be done with:
>
> col=c(rep("black",10),rep("red",10))
>
> depending upon what print function you are using. I suspect that this
> may be based on a value in your data. For example, if you want  black
> for values of some variable up to 10 and red for those over:
>
> col=ifelse(x>10,"red","black)
>
> Jim
>
> On Sun, Mar 28, 2021 at 12:20 AM Mahmood Naderan-Tahan
> <[hidden email]> wrote:
> >
> > Hi
> >
> > I use this command to generate a graph of individuals
> >
> >
> > ind <- get_famd_ind(res.famd)
> > fviz_famd_ind(res.famd, repel = TRUE)
> >
> >
> > I would like to know how can I specify different colors for different individuals?
> >
> > The colorization is not very complex. Basically, I want to specify rows[1:10] to be shown in black and rows[11:20] to be shown in red.
> >
> >
> > Any idea about that?
> >
> >
> > Regards,
> > Mahmood
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [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.
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [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.
Reply | Threaded
Open this post in threaded view
|

Re: Colorizing different individuals with fviz

Mahmood Naderan-Tahan
I understand that I came across this error after that


ind <- get_famd_ind(res.famd)
fviz_famd_ind(res.famd,
              col.ind = ifelse(ind>10,"red","black"),
              repel = TRUE)


Error in ifelse(ind > 10, "red", "black") :
  'list' object cannot be coerced to type 'double'
Calls: fviz_famd_ind -> %in% -> ifelse



I guess ind has (x,y) type and hence "ind>10" is not valid.

I also tried


col.ind = ifelse(ind.x>10,"red","black"),


But got the same error.

Any idea about that?



Regards,
Mahmood

________________________________
From: Bill Dunlap <[hidden email]>
Sent: Monday, March 29, 2021 11:25:30 PM
To: Mahmood Naderan-Tahan
Cc: Jim Lemon; [hidden email]
Subject: Re: [R] Colorizing different individuals with fviz

That error means that fviz_famd_ind has more than one argument that
starts with 'col' and you must type a more complete name to
disambiguate it.  Perhaps col.ind=ifelse(...)?

> args(factoextra::fviz_famd_ind)
function (X, axes = c(1, 2), geom = c("point", "text"),
    repel = FALSE, habillage = "none", palette = NULL,
    addEllipses = FALSE, col.ind = "blue", col.ind.sup = "darkblue",
    alpha.ind = 1, shape.ind = 19, col.quali.var = "black",
    select.ind = list(name = NULL, cos2 = NULL, contrib = NULL),
    gradient.cols = NULL, ...)

On Mon, Mar 29, 2021 at 2:20 PM Mahmood Naderan-Tahan
<[hidden email]> wrote:

>
> Hi Jim,
>
> It seems that the following proposed method doesn't work
>
>
> ind <- get_famd_ind(res.famd)
> fviz_famd_ind(res.famd,
>               col=ifelse(x>10,"red","black"),
>               repel = TRUE)
>
>
> Result is:
>
>
> Error in fviz_famd_ind(res.famd, col = ifelse(x > 10, "red", "black"),  :
>   argument 2 matches multiple formal arguments
>
>
>
> Any idea to fix that?
>
> Regards,
> Mahmood
>
> ________________________________
> From: Jim Lemon <[hidden email]>
> Sent: Saturday, March 27, 2021 9:19:23 PM
> To: Mahmood Naderan-Tahan
> Cc: [hidden email]
> Subject: Re: [R] Colorizing different individuals with fviz
>
> Hi Mahmood,
> What you have specified can be done with:
>
> col=c(rep("black",10),rep("red",10))
>
> depending upon what print function you are using. I suspect that this
> may be based on a value in your data. For example, if you want  black
> for values of some variable up to 10 and red for those over:
>
> col=ifelse(x>10,"red","black)
>
> Jim
>
> On Sun, Mar 28, 2021 at 12:20 AM Mahmood Naderan-Tahan
> <[hidden email]> wrote:
> >
> > Hi
> >
> > I use this command to generate a graph of individuals
> >
> >
> > ind <- get_famd_ind(res.famd)
> > fviz_famd_ind(res.famd, repel = TRUE)
> >
> >
> > I would like to know how can I specify different colors for different individuals?
> >
> > The colorization is not very complex. Basically, I want to specify rows[1:10] to be shown in black and rows[11:20] to be shown in red.
> >
> >
> > Any idea about that?
> >
> >
> > Regards,
> > Mahmood
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [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.
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [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.

        [[alternative HTML version deleted]]

______________________________________________
[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: Colorizing different individuals with fviz

Mahmood Naderan-Tahan
Thanks Jim,

It is now working.


Regards,
Mahmood

________________________________
From: Jim Lemon <[hidden email]>
Sent: Tuesday, March 30, 2021 4:28:50 AM
To: Mahmood Naderan-Tahan
Subject: Re: [R] Colorizing different individuals with fviz

Hi Mahmood,
After scanning the replies and finding the "factoextra" and
"FactoMineR" packages I can say with confidence that the col= argument
won't work. First, the graphic output if via ggplot, and I don't think
that "col=" is a valid argument in that environment.
You seem to be using an object that is a list of matrices. Whether
there is a value in there that will separate your individuals into the
"red" and "black" groups I do not know.
I think that Bill is right, you will have to fall back on something like:

col.ind=c(rep("black",10),rep("red",10))

Jim

On Tue, Mar 30, 2021 at 8:33 AM Mahmood Naderan-Tahan
<[hidden email]> wrote:

>
> I understand that I came across this error after that
>
>
> ind <- get_famd_ind(res.famd)
> fviz_famd_ind(res.famd,
>               col.ind = ifelse(ind>10,"red","black"),
>               repel = TRUE)
>
>
> Error in ifelse(ind > 10, "red", "black") :
>   'list' object cannot be coerced to type 'double'
> Calls: fviz_famd_ind -> %in% -> ifelse
>
>
> I guess ind has (x,y) type and hence "ind>10" is not valid.
>
> I also tried
>
>
> col.ind = ifelse(ind.x>10,"red","black"),
>
>
> But got the same error.
>
> Any idea about that?
>
>
>
>
> Regards,
> Mahmood
>
> ________________________________
> From: Bill Dunlap <[hidden email]>
> Sent: Monday, March 29, 2021 11:25:30 PM
> To: Mahmood Naderan-Tahan
> Cc: Jim Lemon; [hidden email]
> Subject: Re: [R] Colorizing different individuals with fviz
>
> That error means that fviz_famd_ind has more than one argument that
> starts with 'col' and you must type a more complete name to
> disambiguate it.  Perhaps col.ind=ifelse(...)?
>
> > args(factoextra::fviz_famd_ind)
> function (X, axes = c(1, 2), geom = c("point", "text"),
>     repel = FALSE, habillage = "none", palette = NULL,
>     addEllipses = FALSE, col.ind = "blue", col.ind.sup = "darkblue",
>     alpha.ind = 1, shape.ind = 19, col.quali.var = "black",
>     select.ind = list(name = NULL, cos2 = NULL, contrib = NULL),
>     gradient.cols = NULL, ...)
>
> On Mon, Mar 29, 2021 at 2:20 PM Mahmood Naderan-Tahan
> <[hidden email]> wrote:
> >
> > Hi Jim,
> >
> > It seems that the following proposed method doesn't work
> >
> >
> > ind <- get_famd_ind(res.famd)
> > fviz_famd_ind(res.famd,
> >               col=ifelse(x>10,"red","black"),
> >               repel = TRUE)
> >
> >
> > Result is:
> >
> >
> > Error in fviz_famd_ind(res.famd, col = ifelse(x > 10, "red", "black"),  :
> >   argument 2 matches multiple formal arguments
> >
> >
> >
> > Any idea to fix that?
> >
> > Regards,
> > Mahmood
> >
> > ________________________________
> > From: Jim Lemon <[hidden email]>
> > Sent: Saturday, March 27, 2021 9:19:23 PM
> > To: Mahmood Naderan-Tahan
> > Cc: [hidden email]
> > Subject: Re: [R] Colorizing different individuals with fviz
> >
> > Hi Mahmood,
> > What you have specified can be done with:
> >
> > col=c(rep("black",10),rep("red",10))
> >
> > depending upon what print function you are using. I suspect that this
> > may be based on a value in your data. For example, if you want  black
> > for values of some variable up to 10 and red for those over:
> >
> > col=ifelse(x>10,"red","black)
> >
> > Jim
> >
> > On Sun, Mar 28, 2021 at 12:20 AM Mahmood Naderan-Tahan
> > <[hidden email]> wrote:
> > >
> > > Hi
> > >
> > > I use this command to generate a graph of individuals
> > >
> > >
> > > ind <- get_famd_ind(res.famd)
> > > fviz_famd_ind(res.famd, repel = TRUE)
> > >
> > >
> > > I would like to know how can I specify different colors for different individuals?
> > >
> > > The colorization is not very complex. Basically, I want to specify rows[1:10] to be shown in black and rows[11:20] to be shown in red.
> > >
> > >
> > > Any idea about that?
> > >
> > >
> > > Regards,
> > > Mahmood
> > >
> > >         [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > [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.
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [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.

        [[alternative HTML version deleted]]

______________________________________________
[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.