Adding a ggtree object to already existing ggplot with shared y-axis - r

I have the following data and plot:
Data:
structure(list(type = c("mut", "mut", "mut", "mut", "mut", "mut",
"mut", "mut", "gene", "gene", "gene", "gene"), gene = c("gyrA",
"gyrA", "gyrB", "gyrB", "parC", "parC", "parE", "parE", "qnrA1",
"qnrA1", "sul3", "sul3"), type2 = c(1, 1, 1, 1, 1, 1, 1, 1, 2,
2, 2, 2), id = c("2014-01-7234-1-S", "2015-01-3004-1-S", "2014-01-2992-1-S",
"2016-17-299-1-S", "2015-01-2166-1-S", "2014-01-4651-1-S", "2016-02-514-2-S",
"2016-02-402-2-S", "2016-02-425-2-S", "2015-01-5140-1-S", "2016-02-522-2-S",
"2016-02-739-2-S"), result = c("1", "0", "0", "0", "0", "0",
"1", "1", "0", "0", "0", "1"), species = c("Broiler", "Pig",
"Broiler", "Red fox", "Pig", "Broiler", "Wild bird", "Wild bird",
"Wild bird", "Pig", "Wild bird", "Wild bird"), fillcol = c("Broiler_1",
"Pig_0", "Broiler_0", "Red fox_0", "Pig_0", "Broiler_0", "Wild bird_1",
"Wild bird_1", "Wild bird_0", "Pig_0", "Wild bird_0", "Wild bird_1"
)), row.names = c(NA, -12L), class = c("grouped_df", "tbl_df",
"tbl", "data.frame"), vars = "gene", drop = TRUE, indices = list(
0:1, 2:3, 4:5, 6:7, 8:9, 10:11), group_sizes = c(2L, 2L,
2L, 2L, 2L, 2L), biggest_group_size = 2L, labels = structure(list(
gene = c("gyrA", "gyrB", "parC", "parE", "qnrA1", "sul3")), row.names = c(NA,
-6L), class = "data.frame", vars = "gene", drop = TRUE, indices = list(
0:1, 2:3, 4:5, 6:7, 8:9, 10:11), group_sizes = c(2L, 2L,
2L, 2L, 2L, 2L), biggest_group_size = 2L, labels = structure(list(
gene = c("gyrA", "gyrB", "parC", "parE", "qnrA1", "sul3")), row.names = c(NA,
-6L), class = "data.frame", vars = "gene", drop = TRUE)))
Plot:
library(ggplot2)
p1 <- ggplot(test_df, aes(fct_reorder(gene, type2),
factor(id),
fill = fillcol,
alpha = result)) +
geom_tile(color = "white")+
theme_minimal()+
labs(fill = NULL)+
theme(axis.text.x = element_text(angle = 90,
hjust = 1,
vjust = 0.3,
size = 7),
axis.title = element_blank(),
panel.grid = element_blank(),
legend.position = "right")+
guides(alpha = FALSE)+
coord_fixed()
Additionally, I have the following tree object:
structure(list(edge = structure(c(23L, 23L, 22L, 22L, 21L, 21L,
20L, 20L, 19L, 19L, 18L, 18L, 17L, 17L, 16L, 16L, 15L, 15L, 14L,
14L, 13L, 13L, 1L, 3L, 2L, 9L, 22L, 23L, 4L, 5L, 20L, 21L, 11L,
12L, 18L, 19L, 10L, 17L, 8L, 16L, 6L, 7L, 14L, 15L), .Dim = c(22L,
2L)), edge.length = c(2, 2, 0, 0, 2.5, 0.5, 2, 2, 0.75, 0.25,
0.5, 0.5, 2.41666666666667, 0.166666666666667, 3.0625, 0.145833333333333,
3.38888888888889, 0.326388888888889, 3, 3, 0.5, 0.111111111111111
), tip.label = c("2016-02-425-2-S", "2016-02-522-2-S", "2015-01-2166-1-S",
"2016-02-402-2-S", "2016-02-514-2-S", "2016-17-299-1-S", "2016-02-739-2-S",
"2015-01-5140-1-S", "2014-01-2992-1-S", "2014-01-7234-1-S", "2014-01-4651-1-S",
"2015-01-3004-1-S"), Nnode = 11L), class = "phylo", order = "postorder")
Which is plotted like this:
library(ggtree)
p2 <- ggtree(tree)+
geom_treescale()+
geom_tiplab(align = TRUE, linesize = 0, size = 1)+
xlim(0, 4.2)
What I want to do is to combine the tree and the first plot, and order the first plot y-axis after the order in the tree, so that they match. I have tried to use some of the solutions here, but I can't seem to produce the same plot with the facet_plot function. Is there a way to identify maching values on the y-axis on both plots, and then combine them?
This is how I want it to look (approximately):

We need to arrange the tile plot in the same order as the tree plot and then we need to lay the two plots out so they correspond. The first task is relatively straightforward, but I'm not sure how to do the second without some manual tweaking of the layout.
library(tidyverse)
library(ggtree)
library(grid)
library(gridExtra)
p2 <- ggtree(tree)+
geom_treescale()+
geom_tiplab(align = TRUE, linesize = 0, size = 3)+
xlim(0, 4.2)
Now that we've created the tree plot, let's get the ordering of the y axis programmatically. We can do that using ggplot_build to get the plot structure.
p2b = ggplot_build(p2)
We can look at the data for the plot layout by running p2b$data in the console. This outputs a list with the various data frames that represent the plot structure. Looking these over, we can see that the fifth and six data frames have the node labels. We'll use the fifth one (p2b$data[[5]] and order them based on the y column to get a vector of node labels (p2b$data[[5]] %>% arrange(y) %>% pull(label))). Then we'll convert test_df$id to a factor variable with this node ordering.
test_df = test_df %>%
mutate(id = factor(id, levels=p2b$data[[5]] %>% arrange(y) %>% pull(label)))
(As another option, you can get the ordering of the nodes directly from p2 with p2$data %>% filter(isTip) %>% arrange(parent) %>% pull(label))
Now we can generate the tile plot p1 with a node order that corresponds to that of the tree plot.
p1 <- ggplot(test_df, aes(fct_reorder(gene, type2),
factor(id),
fill = fillcol,
alpha = result)) +
geom_tile(color = "white")+
theme_minimal()+
labs(fill = NULL)+
theme(axis.text.x = element_text(angle = 90,
hjust = 1,
vjust = 0.3,
size = 7),
axis.title = element_blank(),
panel.grid = element_blank(),
legend.position = "right")+
guides(alpha = FALSE)+
coord_fixed()
We can see in the plot below that the labels correspond.
grid.arrange(p2, p1, ncol=2)
Now we need to lay out the two plots with only one set of labels and with the node lines matching up vertically with the tiles. I've done this with some manual tweaking below by creating a nullGrob() (basically a blank space below p1) and adjusting the heights argument to get the alignment. The layout can probably be done programmatically, but that would take some additional grob (graphical object) manipulation.
grid.arrange(p2 + theme(plot.margin=margin(0,-20,0,0)),
arrangeGrob(p1 + theme(axis.text.y=element_blank()),
nullGrob(),
heights=c(0.98,0.02)),
ncol=2)

Related

Center facets in ggplot2

I'm plotting geom_smooths in facets grouped by size:
library(ggplot2)
ggplot(df,
aes(x = pos, y = mean_ratio_f ))+
geom_smooth(aes(group = factor(size)), method = "lm", se = FALSE, linewidth = 0.5) +
# facets:
facet_wrap(. ~ size, scales = 'free_x')+
labs(x ="X",
y = "Y")
Unfortunately the last three facets (for size groups 23, 24,and 25) are aligned to the left margin so that there is a gap to their right (which also creates the impression of the whole plot being tilted to the right!):
It appears to me that the issue can be solved by centering the three facets in question (but maybe there are other solutions as well). How can the factes be rearranged so that the last three facets are centered?
Data:
df <- structure(list(size = c(3L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L,
8L, 8L, 9L, 9L, 10L, 10L, 11L, 11L, 12L, 12L, 13L, 13L, 14L,
14L, 15L, 15L, 16L, 16L, 17L, 17L, 18L, 18L, 19L, 19L, 20L, 20L,
21L, 21L, 22L, 22L, 23L, 23L, 24L, 24L, 25L, 25L), pos = c(1.5,
2, 1.5, 2, 1.5, 2, 1.5, 2, 1.5, 2, 1.5, 2, 1.5, 2, 1.5, 2, 1.5,
2, 1.5, 2, 1.5, 2, 1.5, 2, 1.5, 2, 1.5, 2, 1.5, 2, 1.5, 2, 1.5,
2, 1.5, 2, 1.5, 2, 1.5, 2, 1.5, 2, 1.5, 2, 1.5, 2), mean_ratio_f = c(527.899043866778,
1223.75592041265, 26.7055556681507, 1014.99764633205, 6.47082070497567,
863.659744048962, 3.81972089409093, 777.045156006896, 2.46140197567771,
745.040410893806, 2.22400421369641, 759.114492391129, 2.13729390098214,
687.177457687369, 1.98034033753045, 778.931235189388, 1.90373974226176,
718.311850673966, 1.80384197110368, 825.996874022512, 1.81708729221153,
784.264857079573, 1.7777262939807, 752.39972151211, 1.76691331278538,
860.318640599953, 1.75527539730966, 869.777351603508, 1.74520729149527,
880.417441527199, 1.73611317639682, 780.755824759386, 1.78837402005967,
868.750440691095, 1.70425949150671, 804.161284483241, 1.70130414461642,
827.894751207786, 1.6956455656474, 846.217696086233, 1.6805039077424,
796.011388849723, 1.65481637360088, 811.918292989823, 1.67084107927763,
920.002748174406), mean_ratio_f_log = c(6773.00321795844, 17499.3396876788,
91.9407050566451, 14640.9637434847, 0.961390621510839, 12925.4581530315,
0.962105282138507, 11965.2882380283, 0.959588977914962, 11925.034356026,
0.95894420256844, 12389.1090131876, 0.962673236418588, 10291.5804363065,
0.961229361905838, 13564.6305043359, 0.959542208244426, 11807.7801051298,
0.958279155901719, 13222.8288829741, 0.960694717000605, 14050.9037663119,
0.959865919899295, 13196.4602878018, 0.960818003520457, 18197.3072369647,
0.959524692210418, 16167.0124087112, 0.962044614557777, 19156.2703675997,
0.958319770694746, 12192.6024672023, 0.96568915213801, 14355.9254483709,
0.957678872168589, 12384.5704259404, 0.956930859337691, 15515.5122785017,
0.964217350399733, 14886.2543318109, 0.958708854899801, 12105.1755086371,
0.959842413426268, 12265.603237096, 0.954623252993519, 15048.4316206923
)), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), row.names = c(NA,
-46L), groups = structure(list(size = 3:25, .rows = structure(list(
1:2, 3:4, 5:6, 7:8, 9:10, 11:12, 13:14, 15:16, 17:18, 19:20,
21:22, 23:24, 25:26, 27:28, 29:30, 31:32, 33:34, 35:36, 37:38,
39:40, 41:42, 43:44, 45:46), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), row.names = c(NA, -23L), class = c("tbl_df",
"tbl", "data.frame"), .drop = TRUE))
You can set the layout with ggh4x::facet_manual() and then manually adjust any spacing in the gtable that seem superfluous to you.
library(ggplot2)
library(ggh4x)
# Data omitted from reprex for brevity, but taken from question
# df <- structure(...)
# Create layout
design <- matrix(
c(1:20, NA, 21:23, NA),
5, 5, byrow = TRUE
)
# Make plot
p <- ggplot(df, aes(x = pos, y = mean_ratio_f ))+
geom_smooth(aes(group = factor(size)),
method = "lm", se = FALSE, linewidth = 0.5) +
facet_manual(vars(size), design = design, scales = "free_x") +
labs(x ="X", y = "Y")
# Convert to gtable
gt <- ggplotGrob(p)
#> `geom_smooth()` using formula = 'y ~ x'
# Set some widths to zero
# I don't know of a programmatic way to get the right indices
gt$widths[8] <- unit(0, "cm")
# Plotting
grid::grid.newpage(); grid::grid.draw(gt)
Created on 2023-01-10 with reprex v2.0.2
Disclaimer: I'm the author of ggh4x

How to change colours in multiple stacked bar charts in R?

I am trying to construct the stacked bar chart plots. Below you may find the sample data set and a code.
This is the data set:
group;answer;count;proportion
first;1;67;19
first;2;119;33,7
first;3;6;1,7
first;4;116;32,9
first;5;45;12,7
second;1;102;17,1
second;2;197;33,1
second;3;10;1,7
second;4;232;38,9
second;5;55;9,2
third;1;49;12,9
third;2;143;37,7
third;3;1;0,3
third;4;142;37,5
third;5;44;11,6
fourth;1;45;14,9
fourth;2;93;30,7
fourth;3;3;1
fourth;4;118;38,9
fourth;5;44;14,5
This is the code:
p <- ggplot(sample1, aes(y = proportion, x = group, fill = proportion)) +
geom_bar(position = "stack", stat = "identity") +
facet_grid(~ "") +
theme_minimal() +
p1 <- ggpar(p, xlab = F, ylab = F, legend = "", ticks = F)
p1 + geom_text(aes(label = proportion),
position = position_stack(vjust = 0.5),
check_overlap = T,
colour = "white")
This generates the plot well, but I need to manually change the colours of the five categories (in the data set denoted to as "answer").
However, if I add:
scale_fill_manual(values = c("#E7344E", "#0097BF", "#E7344E", "#0097BF", "#E7344E") )
I get the error: Continuous value supplied to discrete scale.
You are mapping a numeric on the fill aes. Hence you get a continuous fill color scale. If you want to fill your bars by answer map this column on the fill aes. But as this column is a numeric too, convert it to factor to make scale_fill_manual work:
library(ggplot2)
p <- ggplot(sample1, aes(y = proportion, x = group, fill = factor(answer))) +
geom_bar(position = "stack", stat = "identity") +
scale_fill_manual(values = c("#E7344E", "#0097BF", "#E7344E", "#0097BF", "#E7344E")) +
facet_grid(~"") +
theme_minimal()
p1 <- ggpubr::ggpar(p, xlab = F, ylab = F, legend = "", ticks = F)
p1 + geom_text(aes(label = proportion),
position = position_stack(vjust = 0.5),
check_overlap = T,
colour = "white"
)
DATA
sample1 <- structure(list(group = c(
"first", "first", "first", "first",
"first", "second", "second", "second", "second", "second", "third",
"third", "third", "third", "third", "fourth", "fourth", "fourth",
"fourth", "fourth"
), answer = c(
1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L,
4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L
), count = c(
67L,
119L, 6L, 116L, 45L, 102L, 197L, 10L, 232L, 55L, 49L, 143L, 1L,
142L, 44L, 45L, 93L, 3L, 118L, 44L
), proportion = c(
19, 33.7,
1.7, 32.9, 12.7, 17.1, 33.1, 1.7, 38.9, 9.2, 12.9, 37.7, 0.3,
37.5, 11.6, 14.9, 30.7, 1, 38.9, 14.5
)), class = "data.frame", row.names = c(
NA,
-20L
))

How modify stacked bar chart in ggplot2 so it is diverging

My data (from a likert scale question) looks like this:
head(dat)
Consideration Importance2 Importance Percent Count
1 Aesthetic value 1 Not at all important 0.046875 3
2 Aesthetic value 2 Of little importance 0.109375 7
3 Aesthetic value 3 Moderately important 0.250000 16
dput(head(dat,6))
structure(list(Consideration = structure(c(2L, 2L, 2L, 2L, 2L,
12L), .Label = c("", "Aesthetic value", "Affordability/cost-efficiency",
"Climate change reduction", "Eco-sourcing", "Ecosystem services provision",
"Erosion mitigation", "Habitat for native wildlife", "Habitat/species conservation",
"Human use values", "Increasing biodiversity", "Planting native species",
"Restoring ecosystem function", "Restoring to a historical state"
), class = "factor"), Importance2 = c(1L, 2L, 3L, 4L, 5L, 1L),
Importance = structure(c(4L, 5L, 3L, 2L, 6L, 4L), .Label = c("",
"Important", "Moderately important", "Not at all important",
"Of little importance", "Very Important"), class = "factor"),
Percent = c(0.046875, 0.109375, 0.25, 0.375, 0.234375, 0),
Count = c(3L, 7L, 16L, 24L, 15L, 0L), percentage = c(5L,
11L, 25L, 38L, 23L, 0L)), row.names = c(NA, 6L), class = "data.frame")
I've plotted the results using a stacked bar chart. I would like to know how to modify this so it's a diverging stacked bar chart such as the example shown below, with the Importance2 level 3 (moderately important) as the centre.
I know there is a package called likert that can be used for this, but I think my data is not in the correct format.
The code for my existing plot is:
ggplot(dat, aes(x = Consideration, y = Percent, fill = forcats::fct_rev(Importance2))) +
geom_bar(position="fill", stat = "identity", color = "black", size = 0.2, width = 0.8) +
aes(stringr::str_wrap(dat$Consideration, 34), dat$Percent) +
coord_flip() +
labs(y = "Percentage of respondents (%)") +
scale_y_continuous(breaks=c(0, 0.25, 0.50, 0.75, 1), labels=c("0", "25", "50", "75", "100")) +
theme(axis.title.y=element_blank(), panel.background = NULL, axis.text.y = element_text(size=8), legend.title = element_text(size=8), legend.text = element_text(size = 6)) +
scale_fill_manual(name="Scale", breaks=c("1", "2", "3", "4", "5"), labels=c("Not at all important", "Of little importance", "Moderately important","Important", "Very important"), values=col3)
I've tried a couple of solution, but I think that the simplest one is to convert your data for the likert() function, and it's quite simple:
library(tidyr)
# you need the data in the wide format
data_l <- spread(dat[,c(1,3,4)], key = Importance, value = Percent)
# now add colnames
row.names(data_l) <- data_l$Consideration
# remove the useless column
data_l <- data_l[,-1]
Now you can use:
library(HH)
likert(data_l , horizontal=TRUE,aspect=1.5,
main="Here the plot",
auto.key=list(space="right", columns=1,
reverse=TRUE, padding.text=2),
sub="Here some words")
You can tweak ggplot to do this, but in that case you do not center by the center of the class you want, but by the "edge" of it.

ggplot change color of one bar from stacked bar chart

Is there way to change colors of one bar( x - value) manualy in ggplot
data
for_plot_test=structure(list(name = c("A", "B",
"C", "A1", "A2", "A3",
"A4", "BI", "A", "B",
"C", "A1", "A2", "A3",
"A4", "BI"), n = c(1L, 3L, 5L, 7L, 9L, 11L, 13L, 15L, 2L, 4L, 6L, 8L, 10L, 12L, 14L, 16L),
value = c(0, 0.05, 0, 0.05, 0.05, 0.1, 0.05, 0, 1, 0.7, 0.6, 0.5, 0.4, 0.2, 0.2, 0.1),
variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L),
.Label = c("PROGRESS", "prev_progress"), class = "factor")),
class = c("grouped_df", "tbl_df", "tbl", "data.frame"),
row.names = c(NA, -16L), vars = "name", labels = structure(list(name = c("Applications", "BI", "Clients", "CRE & Scoring", "Portfolio & Production", "SG Russia", "Transactions", "УКЛ & Prescoring")),
row.names = c(NA, -8L), class = "data.frame", vars = "name", drop = TRUE,
indices = list(0:1, 14:15, 6:7, 10:11, 2:3, 12:13, 8:9, 4:5),
group_sizes = c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L),
biggest_group_size = 2L, .Names = "name"),
indices = list(c(0L, 8L), c(7L, 15L), c(3L, 11L), c(5L, 13L), c(1L, 9L), c(6L, 14L), c(4L, 12L), c(2L, 10L)),
drop = TRUE, group_sizes = c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), biggest_group_size = 2L,
.Names = c("name", "n", "value", "variable"))
Current plot
colot_progress=c("#be877a","#dcbfad")
s <- ggplot(for_plot_test, aes(x= reorder(name, -n),y = value, fill = variable,label=ifelse(for_plot$value==0,"",scales::percent(for_plot$value))))+
geom_bar(stat='identity',position = "stack")+
scale_fill_manual(values=colot_progress,aesthetics = "fill")+
coord_flip()+
theme_minimal() + theme(
axis.title = element_blank(),
axis.text.x=element_blank(),
panel.grid = element_blank(),
legend.position="none"
)+
geom_text(size = 5, position = position_stack(vjust = 0.5))
s
Illustration of desire result
Creating another level for the column variable.
library(dplyr)
for_plot_test1 <-
for_plot_test %>%
group_by(name) %>%
summarise(n = n()) %>%
mutate(value = ifelse(name == "A", 1, 0), variable = "dummy") %>%
full_join(for_plot_test %>% mutate(value = replace(value, name == "A", 0)))
for_plot_test1$variable <- factor(for_plot_test1$variable,
levels = c("dummy", "PROGRESS", "prev_progress"))
colot_progress <- c("limegreen", "#be877a", "#dcbfad")
s <- ggplot(for_plot_test1,
aes(
x = reorder(name,-n),
y = value,
fill = variable,
label = ifelse(value == 0, "", scales::percent(value))
)) +
geom_bar(stat = 'identity', position = "stack") +
scale_fill_manual(values = colot_progress, aesthetics = "fill") +
coord_flip() +
theme_minimal() + theme(
axis.title = element_blank(),
axis.text.x = element_blank(),
panel.grid = element_blank(),
legend.position = "none"
) +
geom_text(size = 5, position = position_stack(vjust = 0.5))
s

igraph pie vertices with defined segment sizes and continuous colors for each segment

I'm trying to create a pie chart in igraph for R, where each vertex is graphed as a pie chart separated into two equal-sized segments and each segment is colored as a gradient from blue to white to red based on two columns. I can create the color gradients for each, but I'm having difficulty figuring out how to map a color gradient to a pie chart. All of the examples I'm finding color pie chart segments based on discrete values, not continuous.
Edit: I've incorporated more information here to create a reproducible example.
library(igraph)
test1 <- structure(list(From.Molecule.s. = c("EIF2AK2", "ELK1", "FOS"),
To.Molecule.s. = c("CHUK", "FOS", "CD14"), Relationship.Type = structure(c(1L,
1L, 2L), .Label = c("activation", "expression", "inhibition",
"phosphorylation", "protein-DNA interactions", "protein-protein interactions",
"protein-RNA interactions", "reaction", "transcription"), class = "factor"),
color = c("Light Coral", "Light Coral", "Goldenrod")), .Names = c("From.Molecule.s.", "To.Molecule.s.", "Relationship.Type", "color"), row.names = c(20L, 23L, 27L), class = "data.frame")
test1_exp <- structure(list(From.Molecule.s. = c("CD14", "CHUK", "ECSIT",
"EIF2AK2", "ELK1", "FOS"), expression.x = c(-0.454, 0.863, -0.326,
0, -0.31, 0), Expr.p.value.x = c(0.198648, 0.003975, 0.164683,
NA, 0.039658, NA), vector_colors.x = structure(c(1L, 11L, 3L,
27L, 5L, 27L), .Label = c("#0000FF", "#2626FF", "#4848FF", "#4D4DFF",
"#4F4FFF", "#5C5CFF", "#9A9AFF", "#F9F9FF", "#FF0000", "#FF1B1D",
"#FF2426", "#FF3C40", "#FF5459", "#FF565B", "#FF585D", "#FF6369",
"#FF7076", "#FF757C", "#FF777E", "#FF7E86", "#FF8992", "#FF9AA3",
"#FF9FA9", "#FFA5AF", "#FFAEB9", "#FFB6C1", "#FFFFFF"), class = "factor"),
expression.y = c(0.271, -0.022, 0.219, 0, 0.126, 0), Expr.p.value.y = c(0.705028,
0.97643, 0.63173, NA, 0.670641, NA), vector_colors.y = structure(c(17L,
15L, 21L, 28L, 23L, 28L), .Label = c("#0000FF", "#4242FF",
"#5A5AFF", "#7676FF", "#7B7BFF", "#9797FF", "#9D9DFF", "#A7A7FF",
"#ACACFF", "#C6C6FF", "#D0D0FF", "#D8D8FF", "#EFEFFF", "#F2F2FF",
"#F4F4FF", "#FF0000", "#FF282A", "#FF2A2C", "#FF3134", "#FF4044",
"#FF4448", "#FF5257", "#FF777E", "#FF8B94", "#FF8F98", "#FFB0BB",
"#FFB6C1", "#FFFFFF"), class = "factor")), .Names = c("From.Molecule.s.",
"expression.x", "Expr.p.value.x", "vector_colors.x", "expression.y",
"Expr.p.value.y", "vector_colors.y"), row.names = c(NA, 6L), class = "data.frame")
TLR <- graph_from_data_frame(test1, directed = T,vertices = test1_exp)
V(TLR)$size=7.5
V(TLR)$label.cex=0.8
V(TLR)$label.dist=0.75
V(TLR)$label.degree = pi/2
V(TLR)$label.color = "black"
TLR_net <- plot(TLR,edge.arrow.size = 0.15,vertex.shape = "pie",vertex.pie.color = c(V(TLR)$vector_colors.x,V(TLR)$vector_colors.y))
And what the test output looks like now:

Resources