geom_node_point color in ggraph

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

geom_node_point color in ggraph

Wolfgang Grond
Dear all,

I'm joining differnts graphs to one with command graph_join from ggraph,

and try to color the nodes depending on the subgraph they come from.

To do that, I have these commands in my ggraph:

####################################################

...
geom_node_point(size = 8, aes(colour = project_all$Acronym)) +
     scale_color_discrete(name="Project / Projekt") +
...

####################################################

All works well, but

how to define the colors to use for the nodes?

Is it possible to either

- define the colors explicitely, or

- define a color palette to use?

Please point me to where I should look how to do it.

Many thanks in advance

Wolfgang


        [[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: geom_node_point color in ggraph

Rui Barradas
Hello,

To define the colors, remove the data set name from the aesthetic.
This

aes(colour = project_all$Acronym)


should be this

aes(colour = Acronym)


Then choose the colours in the usual ggplot way. Here is a reproducible
example.


library(igraph)
library(ggraph)

project_all <- make_graph("bull")
vertex_attr(project_all, "Acronym", index = V(project_all)) <- "red"
vertex_attr(project_all, "Acronym", index = V(project_all)[[3]]) <- "blue"

ggraph(project_all, layout = "igraph", algorithm = "kk") +
   geom_edge_link() +
   geom_node_point(aes(colour = Acronym), size = 8) +
   scale_color_manual(name = "Project / Projekt",
                      values = c("blue", "red"))


Hope this helps,

Rui Barradas


Às 15:57 de 15/04/21, Wolfgang Grond escreveu:

> Dear all,
>
> I'm joining differnts graphs to one with command graph_join from ggraph,
>
> and try to color the nodes depending on the subgraph they come from.
>
> To do that, I have these commands in my ggraph:
>
> ####################################################
>
> ...
> geom_node_point(size = 8, aes(colour = project_all$Acronym)) +
>       scale_color_discrete(name="Project / Projekt") +
> ...
>
> ####################################################
>
> All works well, but
>
> how to define the colors to use for the nodes?
>
> Is it possible to either
>
> - define the colors explicitely, or
>
> - define a color palette to use?
>
> Please point me to where I should look how to do it.
>
> Many thanks in advance
>
> Wolfgang
>
>
> [[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: geom_node_point color in ggraph

Wolfgang Grond-2
Rui,

thanks a lot, I'll try it this way.

Best regards

Wolfgang

Am 15. April 2021 21:19:27 MESZ schrieb Rui Barradas <[hidden email]>:

>Hello,
>
>To define the colors, remove the data set name from the aesthetic.
>This
>
>aes(colour = project_all$Acronym)
>
>
>should be this
>
>aes(colour = Acronym)
>
>
>Then choose the colours in the usual ggplot way. Here is a reproducible
>
>example.
>
>
>library(igraph)
>library(ggraph)
>
>project_all <- make_graph("bull")
>vertex_attr(project_all, "Acronym", index = V(project_all)) <- "red"
>vertex_attr(project_all, "Acronym", index = V(project_all)[[3]]) <-
>"blue"
>
>ggraph(project_all, layout = "igraph", algorithm = "kk") +
>   geom_edge_link() +
>   geom_node_point(aes(colour = Acronym), size = 8) +
>   scale_color_manual(name = "Project / Projekt",
>                      values = c("blue", "red"))
>
>
>Hope this helps,
>
>Rui Barradas
>
>
>Às 15:57 de 15/04/21, Wolfgang Grond escreveu:
>> Dear all,
>>
>> I'm joining differnts graphs to one with command graph_join from
>ggraph,
>>
>> and try to color the nodes depending on the subgraph they come from.
>>
>> To do that, I have these commands in my ggraph:
>>
>> ####################################################
>>
>> ...
>> geom_node_point(size = 8, aes(colour = project_all$Acronym)) +
>>       scale_color_discrete(name="Project / Projekt") +
>> ...
>>
>> ####################################################
>>
>> All works well, but
>>
>> how to define the colors to use for the nodes?
>>
>> Is it possible to either
>>
>> - define the colors explicitely, or
>>
>> - define a color palette to use?
>>
>> Please point me to where I should look how to do it.
>>
>> Many thanks in advance
>>
>> Wolfgang
>>
>>
>> [[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.

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