Related
[[Reproducible data for this question is found at bottom of question.]]
When plotting a network with qgraph, the edges usually link to nodes in a relatively straightforward way.
library(qgraph)
qgraph(Network)
But as soon as I add a size to my nodes, the edges often overshoot the nodes:
qgraph(Network,
vsize=log(Attributes)*3, # scale nodes
vTrans=150, #Transparency of the nodes
label.scale=F # don't scale labels along with nodes
)
Some node scaling sizes work better than others:
qgraph(Network,vsize=Attributes/5,
vTrans=150,#Transparency of the nodes, must be an integer between 0 and 255, 255 indicating no transparency
label.scale=F)
But it isn't clear why this is the case, or how I can override the edges to meet the node appropriately (either at the boundary of the scaled node or at the centerpoint of the node). Any thoughts welcome.
Data:
Network<-structure(list(V4 = c(0, 0, 0.6, 0.01, 0.06, 0.09, 0.01, 0.01,
0, 0.01, 0.03, 0, 0, 0, 0.12, 0.04, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), V5 = c(0, 0, 0.6,
0.01, 0.06, 0.09, 0.01, 0.01, 0, 0.01, 0.03, 0, 0, 0, 0.13, 0.04,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0), V6 = c(0, 0, 0, 0.02, 0.12, 0.08, 0, 0.01, 0, 0.01, 0.02,
0, 0, 0, 0.04, 0.02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0), V7 = c(0, 0, 0, 0, 0, 0, 0.01, 0.01,
0.01, 0.03, 0.01, 0.03, 0.05, 0, 0.03, 0, 0, 0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0, 0.02, 0, 0.02, 0, 0, 0), V60 = c(0, 0, 0, 0, 0,
0, 0, 0, 0.01, 0.02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.02,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0.02, 0.04, 0, 0, 0, 0), V61 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0.01, 0, 0, 0, 0, 0, 0, 0), V62 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.06, 0.04, 0.01, 0, 0),
V63 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0.03, 0.01, 0, 0, 0)), class = "data.frame", row.names = c("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", "47", "48",
"49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
"60", "61", "62", "63"))
Attributes<-c(34.93768692, 4.75733614, 13.93967533, 2.833557367, 8.325469971,
8.177970886, 2.928951502, 2.174068213, 7.494392872, 6.128136158,
2.818100929, 1.909636378, 3.748121262, 1e-05, 70.72342682, 22.41350937,
2.115944386, 0.005, 1.84581995, 0.102126002, 15.20289135, 2.613022089,
4.338716984, 0.032485999, 0.059714999, 0.080463, 0.035101, 0.011345,
1, 3.151705027, 0.239722997, 0.137802005, 0.017914001, 0.036782667,
1.388822675, 0.435640007, 3.397774458, 2.329986095, 21.80796051,
0.200000003, 1.358244658, 0.687838018, 2.832928419, 1.016921043,
11.10915184, 2.84529686, 0.925952315, 4.18819809, 3.080216408,
0.276921213, 1.808943033, 3.043907881, 0.426636606, 80, 3.872853518,
7.236839294, 1.322934866, 11.1804142, 3.803627491, 31.66708755
)
The edges aren't necessarily wrong. You've given many of the nodes negative values. if you even set them to 1, the arrows do as you expect. For example, vsize = ifelse(log(Attributes) * 3 > 0, log(Attributes) * 3, 1) will present with all meaningful arrows.
I'm surprised it didn't cause an error when you made the nodes negative... it's actually really nice that it didn't. It probably made it a lot easier to figure out what was wrong. When you used Attributes/5 you didn't end up with negative values.
I have fish stomach contents/diet data and I would like to get presence/absence information for each taxa in my df by month. Each observation (row) has information on the taxa absent (== 0) or present (== 1) in each fish's stomach. I have already transformed my original data to presence/absence values, however, I am not sure how to obtain a summary of what taxa was present or absent by month.
structure(list(id = c("607_6", "808_4", "801_3", "807_11", "801_16",
"724_13", "1030_40", "723_78", "701_4", "634_2", "1023_2", "1031_2",
"643_4", "606_3", "723_79", "801_4", "629_4", "642_10", "801_10",
"801_11", "1001_35", "616_4", "701_9", "627_2", "601_5"), Daphnia = c(0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0), Byths = c(0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0,
1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1), Chiro.Pupae = c(0, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0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 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0), Cyclopoid = c(0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Fish.Eggs = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0), EggMass = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Dreissena = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0), Goby = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Eurycercidae = c(0,
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0), Hirudinea = c(0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), totalnumPrey = c(0,
5, 0, 0, 102, 7, 220, 45, 0, 0, 0, 25, 116, 49, 119, 0, 7,
5, 0, 0, 0, 595, 105, 58, 20), MONTH = c(6L, 8L, 8L, 8L,
8L, 7L, 11L, 7L, 7L, 6L, 11L, 11L, 6L, 6L, 7L, 8L, 6L, 6L,
8L, 8L, 11L, 6L, 7L, 6L, 6L), empty = c("Empty", "Not_empty",
"Empty", "Empty", "Not_empty", "Not_empty", "Not_empty",
"Not_empty", "Empty", "Empty", "Empty", "Not_empty", "Not_empty",
"Not_empty", "Not_empty", "Empty", "Not_empty", "Not_empty",
"Empty", "Empty", "Empty", "Not_empty", "Not_empty", "Not_empty",
"Not_empty")), row.names = c(NA, -25L), class = c("data.table",
"data.frame"))
I looked online and various SO posts like this one, but I am not getting exactly what I need.
I would like to end up with something like this (or similar) for each month for all taxa in my df (the values here are made up, might not reflect the real data):
Month
Daphnia
Byths
Chiro.Pupae
Isopod
Goby
11
1
1
0
1
0
My ultimate goal is to make a bar plot in ggplot that looks like this:
Originally, the data was in long format but this results in multiple rows per fish. I changed to wide format to end up with one observation(row) per fish.
How can I achieve this to ultimately plot presence/absence by month? Thank you!
Maybe you want something like with your selected column converted to a longer format. After that to show the zeros bars, you can say that there is a bar by giving it a small negative number (if you want to show zero bars). At last, the y-axis has a binary format. You can use the following code:
library(dplyr)
library(ggplot2)
library(tidyr)
library(lubridate)
df %>%
select(MONTH, Daphnia, Byths, Chiro.Pupae, Isopod, Goby) %>%
mutate(MONTH = month.name[MONTH]) %>%
pivot_longer(cols = -c(MONTH), values_transform = as.numeric) %>%
ggplot(aes(x = MONTH, y = sapply(value, FUN=function(x) ifelse(x==0,-0.1,x)), fill = name)) +
geom_bar(position = "dodge", stat = "identity") +
scale_y_continuous(breaks = c(0,1)) +
labs(y = "Absence", x = "Month")
Created on 2022-07-30 by the reprex package (v2.0.1)
I'm looking to make a graph similar to this one:
Where not only do the vertices have different sizes according to their values, but the edges have different widths according to the values/force.
I have this data set here:
data = structure(c(NA, 0, 0, 0, 0.003122927, 0.00999241, 0.008685473,
0.007730365, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.003573423, 0, 0, 0,
0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.18893711, 0, 0, 0, NA, 0.183237263,
0.139293056, 0.120902907, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.132071652,
0, 0.457142857, 0.114500717, 0.322255215, 0, 0, 0, 0.097676062,
NA, 0.261095249, 0.131416203, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.146191646,
0, 0, 0, 0, 0.086854728, 0, 0, 0, 0.023023646, 0.080959767, NA,
0.034786642, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.09469697,
0, 0, 0, 0.024480341, 0.049917782, 0.042613636, NA, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0.255554962, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.765625,
0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0,
0, 0.040201005, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.041930937, 0, 0.192970073,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0.030562035,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0,
0, 0, 0, 0, 0, 0.151121606, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, NA, 0.039751553, 0, 0, 0, 0, 0, 0.026693325, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.011428571, NA), .Dim = c(23L,
23L), .Dimnames = list(c("sp1", "sp2", "sp3", "sp4", "sp5", "sp6",
"sp7", "sp8", "sp9", "sp10", "sp11", "sp12", "sp13", "sp14",
"sp15", "sp16", "sp17", "sp18", "sp19", "sp20", "sp21", "sp22",
"sp23"), c("sp1", "sp2", "sp3", "sp4", "sp5", "sp6", "sp7", "sp8",
"sp9", "sp10", "sp11", "sp12", "sp13", "sp14", "sp15", "sp16",
"sp17", "sp18", "sp19", "sp20", "sp21", "sp22", "sp23")))
This is my script:
library (igraph)
View (data)
class (data)
data= data.matrix(data, rownames.force = NA)
class (data)
graph <- graph_from_adjacency_matrix(data, mode = "directed", weighted = TRUE)
as_edgelist(graph, names=F)
as_adjacency_matrix(graph, attr="weight")
as_data_frame(graph, what="edges")
as_data_frame(graph, what="vertices")
graph = simplify(graph, edge.attr.comb=list(weight="sum","ignore"))
deg <- degree(graph, mode="all")
L <- layout_in_circle(graph)
plot(graph, edge.arrow.size=.1, vertex.color="black",vertex.size=deg*1.5,
vertex.frame.color="black", vertex.label.color="grey10", vertex.label.degree=-pi/6,
vertex.shape="circle",vertex.label.cex=1, vertex.label.dist=2,
vertex.label.font=1, edge.arrow.size=8, edge.width=0, edge.curved=0, edge.color="black",
edge.lty=1, layout=L)
This code above generated this graph for me:
Can someone help me? I'm really confused about that. I don't have much experience with graphs. Thank you.
I have a dataframe of over 200 variables, many of which end with a code for a given species. I want to eliminate any columns that contain one of several codes, contained in a separate vector of character strings. How can I remove these multiple columns matching the multiple codes at the same time? The column names don't match the code values exactly, but contain the codes at the end of the column name. For example:
"rev230" "rev3360" "rev3508"
Manually, I've done this (using the dplyr package):
sub = select(df, -contains("3781"), -contains("3751"), -contains("1408"),
-contains("1409"), -contains("4469"), -contains("1789"), -contains("4559"),
-contains("1453"),-contains("8"), -contains("3508"), -contains("4656"),
-contains("5131"), -contains("9999"))
This gets me what I want (eliminating all columns that contain data on the species matching these codes), but obviously this is very tedious.
I'd like something more like:
sub = select(df, -contains(species$codes))
# I realize this isn't the right syntax
I tried a loop to remove individual columns, using something like this:
foreach(i=1:length(species$codes), .combine=rbind)%do%
select(df, -contains(species$codes[i]))
but that didn't work either. Thanks in advance!
reproducible example:
Species codes (contained in a character vector):
dput(species)
c("3754", "3755", "3758", "3764", "3765", "3771", "3772", "3782",
"3761", "3762", "3763", "3767", "3768", "1790", "1412", "1413",
"1416", "1422", "1423", "1424", "1425", "1426", "1410", "1411",
"1414", "1415", "1420", "3770", "4740", "4470", "4472", "4474",
"4476", "4479", "4480", "1812", "1815", "1799", "4560", "3810",
"1440", "1441", "3302", "3295", "3560", "3360", "1940", "3840",
"570", "1050", "4710", "230")
Here are the first 10 rows of the data, with only columns for species data
dput(logsub)
structure(list(lbs3781 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 708), lbs3764 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), lbs3765 = c(0, 0, 0, 0, 0, 0, 0,
0, 0, 708), lbs3758 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), lbs3755 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), lbs3782 = c(0, 0, 0, 0, 0, 0, 0,
0, 0, 0), lbs3751 = c(0, 0, 4, 0, 0, 0, 21, 0, 18, 0), lbs3761 = c(0,
0, 0, 0, 0, 0, 18, 0, 0, 0), lbs3762 = c(0, 0, 4, 0, 0, 0, 3,
0, 0, 0), lbs3763 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), lbs3767 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), lbs3768 = c(0, 0, 0, 0, 0, 0, 0,
0, 0, 0), lbs3754 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), lbs3771 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), lbs3772 = c(0, 0, 0, 0, 0, 0, 0,
0, 0, 0), lbs1790 = c(0, 0, 0, 0, 0, 0, 0, 0, 18, 0), lbs1409 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 86), lbs1411 = c(0, 0, 0, 0, 0, 0, 0,
0, 0, 0), lbs1414 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), lbs1415 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 86), lbs4740 = c(0, 0, 0, 0, 0, 0, 0,
0, 0, 0), lbs1420 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), lbs3770 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), lbs1408 = c(2508, 785, 57, 0, 132,
5003, 18, 104, 636, 0), lbs1412 = c(0, 0, 0, 0, 0, 0, 0, 0, 0,
0), lbs1413 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), lbs1416 = c(2331,
654, 57, 0, 81, 4284, 15, 104, 120, 0), lbs1422 = c(177, 0, 0,
0, 51, 719, 3, 0, 0, 0), lbs1423 = c(0, 131, 0, 0, 0, 0, 0, 0,
502, 0), lbs1424 = c(0, 0, 0, 0, 0, 0, 0, 0, 14, 0), lbs1425 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), lbs1426 = c(0, 0, 0, 0, 0, 0, 0,
0, 0, 0), lbs1410 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), lbs4469 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), lbs4470 = c(0, 0, 0, 0, 0, 0, 0,
0, 0, 0), lbs4472 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L),
lbs4474 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), lbs4476 = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), lbs4479 = c(0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), lbs4480 = c(0, 0, 0, 0,
0, 0, 0, 0, 0, 0), lbs1789 = c(0, 0, 0, 863, 0, 0, 0, 0,
0, 98), lbs1812 = c(0, 0, 0, 863, 0, 0, 0, 0, 0, 27), lbs1815 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 71), lbs1799 = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 0), lbs4559 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 12),
lbs4560 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 12), lbs3810 = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), lbs1453 = c(0, 0, 5,
0, 0, 0, 21, 0, 15, 235), lbs1440 = c(0, 0, 5, 0, 0, 0, 21,
0, 15, 0), lbs1441 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), lbs3560 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), lbs3302 = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 235), lbs3295 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
lbs0008 = c(0, 97, 99, 0, 0, 0, 0, 0, 0, 0), lbs1940 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), lbs3840 = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 0), lbs1050 = c(0, 0, 31, 0, 0, 0, 0, 0, 0, 0),
lbs4710 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), lbs570 = c(0,
97, 68, 0, 0, 0, 0, 0, 0, 0), lbs230 = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 0), lbs3360 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), lbs3508 = c(0,
0, 5043, 0, 0, 0, 0, 0, 0, 0), lbs4656 = c(0, 0, 0, 0, 0,
0, 0, 0, 0, 0), lbs9999 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
rev3781 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 1688.144979), rev3764 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), rev3765 = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 1688.144979), rev3758 = c(0, 0, 0, 0, 0, 0, 0, 0,
0, 0), rev3755 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), rev3782 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), rev3751 = c(0, 0, 7.063636364,
0, 0, 0, 33.44605263, 0, 32.53608247, 0), rev3761 = c(0,
0, 0, 0, 0, 0, 27.34105263, 0, 0, 0), rev3762 = c(0, 0, 7.063636364,
0, 0, 0, 6.105, 0, 0, 0), rev3763 = c(0, 0, 0, 0, 0, 0, 0,
0, 0, 0), rev3767 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), rev3768 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), rev3754 = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 0), rev3771 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), rev3772 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), rev1790 = c(0, 0, 0, 0, 0, 0,
0, 0, 32.53608247, 0), rev1409 = c(0, 0, 0, 0, 0, 0, 0, 0,
0, 260.0068669), rev1411 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0
), rev1414 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), rev1415 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 260.0068669), rev4740 = c(0, 0, 0,
0, 0, 0, 0, 0, 0, 0), rev1420 = c(0, 0, 0, 0, 0, 0, 0, 0,
0, 0), rev3770 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), rev1408 = c(6349.327025,
2014.2837, 142.8362084, 0, 339.5618788, 13265.98305, 41.94345809,
235.6862428, 1835.487932, 0), rev1412 = c(0, 0, 0, 0, 0,
0, 0, 0, 0, 0), rev1413 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
rev1416 = c(5841.249152, 1623.155767, 142.8362084, 0, 194.2835976,
11101.38378, 33.99320809, 235.6862428, 299.2968186, 0), rev1422 = c(508.0778723,
0, 0, 0, 145.2782813, 2164.599274, 7.95025, 0, 0, 0), rev1423 = c(0,
391.1279328, 0, 0, 0, 0, 0, 0, 1494.676782, 0), rev1424 = c(0,
0, 0, 0, 0, 0, 0, 0, 41.51433134, 0), rev1425 = c(0, 0, 0,
0, 0, 0, 0, 0, 0, 0), rev1426 = c(0, 0, 0, 0, 0, 0, 0, 0,
0, 0), rev1410 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), rev4469 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), rev4470 = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 0), rev4472 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), rev4474 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), rev4476 = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 0), rev4479 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L), rev4480 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), rev1789 = c(0,
0, 0, 963.8520574, 0, 0, 0, 0, 0, 95.34540063), rev1812 = c(0,
0, 0, 963.8520574, 0, 0, 0, 0, 0, 30.02711217), rev1815 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 65.31828847), rev1799 = c(0, 0, 0,
0, 0, 0, 0, 0, 0, 0), rev4559 = c(0, 0, 0, 0, 0, 0, 0, 0,
0, 12.94965112), rev4560 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 12.94965112
), rev3810 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), rev1453 = c(0,
0, 3.505617978, 0, 0, 0, 13.9460241, 0, 10.93726937, 225.778089
), rev1440 = c(0, 0, 3.505617978, 0, 0, 0, 13.9460241, 0,
10.93726937, 0), rev1441 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0
), rev3560 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), rev3302 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 225.778089), rev3295 = c(0, 0, 0,
0, 0, 0, 0, 0, 0, 0), rev0008 = c(0, 180.3441341, 169.7750491,
0, 0, 0, 0, 0, 0, 0), rev1940 = c(0, 0, 0, 0, 0, 0, 0, 0,
0, 0), rev3840 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), rev1050 = c(0,
0, 48.71428571, 0, 0, 0, 0, 0, 0, 0), rev4710 = c(0, 0, 0,
0, 0, 0, 0, 0, 0, 0), rev570 = c(0, 180.3441341, 121.0607634,
0, 0, 0, 0, 0, 0, 0), rev230 = c(0, 0, 0, 0, 0, 0, 0, 0,
0, 0), rev3360 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), rev3508 = c(0,
0, 2620.957866, 0, 0, 0, 0, 0, 0, 0), rev4656 = c(0, 0, 0,
0, 0, 0, 0, 0, 0, 0), rev9999 = c(0, 0, 0, 0, 0, 0, 0, 0,
0, 0)), .Names = c("lbs3781", "lbs3764", "lbs3765", "lbs3758",
"lbs3755", "lbs3782", "lbs3751", "lbs3761", "lbs3762", "lbs3763",
"lbs3767", "lbs3768", "lbs3754", "lbs3771", "lbs3772", "lbs1790",
"lbs1409", "lbs1411", "lbs1414", "lbs1415", "lbs4740", "lbs1420",
"lbs3770", "lbs1408", "lbs1412", "lbs1413", "lbs1416", "lbs1422",
"lbs1423", "lbs1424", "lbs1425", "lbs1426", "lbs1410", "lbs4469",
"lbs4470", "lbs4472", "lbs4474", "lbs4476", "lbs4479", "lbs4480",
"lbs1789", "lbs1812", "lbs1815", "lbs1799", "lbs4559", "lbs4560",
"lbs3810", "lbs1453", "lbs1440", "lbs1441", "lbs3560", "lbs3302",
"lbs3295", "lbs0008", "lbs1940", "lbs3840", "lbs1050", "lbs4710",
"lbs570", "lbs230", "lbs3360", "lbs3508", "lbs4656", "lbs9999",
"rev3781", "rev3764", "rev3765", "rev3758", "rev3755", "rev3782",
"rev3751", "rev3761", "rev3762", "rev3763", "rev3767", "rev3768",
"rev3754", "rev3771", "rev3772", "rev1790", "rev1409", "rev1411",
"rev1414", "rev1415", "rev4740", "rev1420", "rev3770", "rev1408",
"rev1412", "rev1413", "rev1416", "rev1422", "rev1423", "rev1424",
"rev1425", "rev1426", "rev1410", "rev4469", "rev4470", "rev4472",
"rev4474", "rev4476", "rev4479", "rev4480", "rev1789", "rev1812",
"rev1815", "rev1799", "rev4559", "rev4560", "rev3810", "rev1453",
"rev1440", "rev1441", "rev3560", "rev3302", "rev3295", "rev0008",
"rev1940", "rev3840", "rev1050", "rev4710", "rev570", "rev230",
"rev3360", "rev3508", "rev4656", "rev9999"), row.names = c(34367L,
48646L, 48715L, 48717L, 48722L, 48724L, 48743L, 48744L, 48781L,
48783L), class = "data.frame")
One options is select_if with grepl, as grepl returns a logical vector and you can include multiple patterns you want to match on via |.
A simple case where you want to remove two species would look like:
select_if(df, !grepl("3781|3751", names(df)) )
Aggregate all of your species into the right form for grepl via paste with collapse, and then use this within grepl.
select_if(df, !grepl(paste(species, collapse = "|"), names(df)) )
I would like to run the whole code in the loop because there will be much more tables than one as in the example. I don't have much experience in doing loops so I'd be so grateful for the help.
That's the code which I would like to run in the loop:
cluster1 <- tbl_cluster[tbl_cluster$fit.cluster == 1,]
cluster1 <- cluster1[,-25]
cluster1 <- as.matrix(cluster1[,2:24])
mode(cluster1)<-"numeric"
heatmap.2(cluster1,
Colv = NA,
scale = "none",
dendrogram = "row",
col=rainbow(256, s = 1, v = 1, start = 0, end = 2/6, alpha = 1),
density.info = "none",
trace = "none",
key = FALSE,
cexCol=0.5,
cexRow=1)
mtext(paste("Cluster 1",""), side=3, line=-1, cex=2, col="black")
mtext("Size in kDa", side=1, line=3.5, cex=1.3, col="black")
I would like to create a pdf file and keep all of those heatmaps in the same pdf, just each heatmap on new page.
In total there is 50 clusters: cluster1, cluster2, cluster3 and so on...
If I have to do it manually and I would write next code like that:
cluster2 <- tbl_cluster[tbl_cluster$fit.cluster == 2,]
cluster2 <- cluster1[,-25]
cluster2 <- as.matrix(cluster2[,2:24])
mode(cluster2)<-"numeric"
heatmap.2(cluster2,
Colv = NA,
scale = "none",
dendrogram = "row",
col=rainbow(256, s = 1, v = 1, start = 0, end = 2/6, alpha = 1),
density.info = "none",
trace = "none",
key = FALSE,
cexCol=0.5,
cexRow=1)
mtext(paste("Cluster 2",""), side=3, line=-1, cex=2, col="black")
mtext("Size in kDa", side=1, line=3.5, cex=1.3, col="black")
Cluster1:
> dput(cluster1)
structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.16752067, 0, 0, 0, 0, 0, 0,
0, 1, 0.663889907, 0.44201215, 1, 0.955735729, 0.746154794, 0.805581104,
1, 0.535148598, 1, 0.750189517, 0.531915145, 0.904554192, 0.580052296,
0.584708494, 0.50381622, 1, 0.689930171, 1, 0.492607902, 0.592845546,
0.784022307, 0.713841276, 0.735311924, 0.485931998, 0.555872624,
0.637681873, 1, 0.608332643, 0.471510245, 0.742100525, 1, 0.725036951,
0.636103642, 0.442522885, 0.781087935, 0.63953839, 1, 1, 0.46976386,
1, 1, 1, 0.75983123, 1, 0.86259757, 1, 1, 0.7087314, 1, 1, 1,
0.50654411, 1, 0.69987908, 1, 1, 1, 1, 1, 1, 1, 1, 0.74120003,
1, 1, 1, 0.73758981, 1, 1, 1, 1, 0.64615661, 0.83194495, 0.80859968,
0.51178152, 0.33254192, 0.44084187, 0.32018398, 0.60794852, 0.55977902,
0.53444753, 0.75018952, 0.76595757, 0.7087314, 0.63280451, 0.58470849,
0.31688716, 0.50654411, 0.68993017, 0.45147891, 0.6658817, 0.60364123,
0.49194389, 0.55370463, 0.48847424, 0.44031246, 0.55587262, 0.60699513,
0.58036173, 0.54545093, 0.44738082, 0.51232832, 0.5531822, 0.35779526,
0.45525701, 0.75091808, 0.72445096, 0, 0.065540432, 0, 0, 0.498637407,
0.099666444, 0.267858247, 0.160618801, 0.036112045, 0.10206614,
0, 0.053537577, 0.292234638, 0.615220442, 0.526821051, 0.245979954,
0.209517328, 0, 0, 0.174034334, 0.145034071, 0.240228383, 0.167734427,
0, 0.243614373, 0.358657498, 0.565901472, 0.134088752, 0.204292959,
0, 0.370633918, 0.153763271, 0, 0.136791753, 0.100906512, 0,
0, 0, 0, 0, 0, 0.029860988, 0.192836939, 0.01099398, 0, 0, 0,
0.044629467, 0.219880408, 0, 0, 0.165085571, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0.208989308, 0.355930559, 0.054875021, 0, 0.278744359,
0.094030066, 0, 0.202269046, 0, 0, 0, 0, 0, 0, 0, 0, 0.31009524,
0, 0, 0, 0, 0, 0, 0, 0, 0.16273216, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0.23948029, 0, 0, 0, 0, 0, 0, 0.38456462, 0, 0, 0, 0, 0, 0,
0, 0, 0.31366311, 0, 0, 0, 0, 0, 0, 0, 0, 0.16376326, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0.14738849, 0, 0, 0, 0, 0, 0, 0.13396394,
0, 0, 0, 0, 0, 0, 0, 0, 0.28847861, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.08922821, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0), .Dim = c(36L, 23L), .Dimnames = list(c("at1g02140.1",
"at1g06130.2", "at1g08110.3", "at1g09830.1", "at1g11930.2", "at1g32470.1",
"at1g47128.1", "at1g62380.1", "at1g66430.1", "at1g75270.1", "at2g25070.1",
"at2g37660.1", "at2g42590.1", "at2g47450.1", "at3g01520.1", "at3g02780.1",
"at3g07470.1", "at3g07720.1", "at3g15840.4", "at3g19010.1", "at3g21750.1",
"at3g29185.1", "at4g00490.1", "at4g16770.1", "at4g29590.1", "at4g37000.1",
"at4g39260.1", "at4g39970.1", "at5g04430.1", "at5g12210.2", "at5g24400.1",
"at5g36160.1", "at5g59420.1", "at5g63980.1", "at5g66530.2", "at5g67150.1"
), c("X20", "X52.5", "X81", "X110", "X140.5", "X189", "X222.5",
"X278", "X340", "X397", "X453.5", "X529", "X580", "X630.5", "X683.5",
"X735.5", "X784", "X832", "X882.5", "X926.5", "X973", "X1108",
"X1200")))
And that's how cluster2 looks like before removing one column and set it as a matrix:
> dput(cluster2)
structure(list(X10 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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 0.17105234, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.43856849, 0, 0, 0, 0, 0, 0.2103673,
0, 0, 0, 0, 0.3364729, 0, 0, 0, 0, 0, 0, 0, 0, 0.13032743, 0,
0, 0, 0, 0.27423546, 0, 0, 0, 0.28894321, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), X453.5 = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0.03595661, 0, 0, 0, 0, 0.17105234,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.08335904,
0, 0, 0, 0, 0.3364729, 0, 0, 0, 0, 0, 0, 0, 0, 0.13032743, 0,
0, 0, 0, 0, 0, 0, 0, 0.03243995, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0), X529 = c(0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0.02518973, 0, 0, 0, 0, 0.118128928, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.004797445,
0, 0, 0, 0, 0.291561006, 0, 0, 0, 0, 0, 0, 0, 0, 0.04657268,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0), X580 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0.037388639, 0, 0, 0, 0, 0, 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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), fit.cluster = c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L)), .Names = c("X10", "X20", "X52.5", "X81",
"X110", "X140.5", "X189", "X222.5", "X278", "X340", "X397", "X453.5",
"X529", "X580", "X630.5", "X683.5", "X735.5", "X784", "X832",
"X882.5", "X926.5", "X973", "X1108", "X1200", "fit.cluster"), row.names = c("at1g02880.3",
"at1g03210.1", "at1g03900.1", "at1g11090.1", "at1g11360.4", "at1g18210.2",
"at1g21600.2", "at1g26520.1", "at1g29260.1", "at1g32550.1", "at1g34760.2",
"at1g44790.1", "at1g56430.1", "at1g60000.1", "at1g62480.1", "at1g71790.1",
"at1g73530.1", "at1g75690.1", "at1g77122.1", "at1g79790.2", "at2g02390.1",
"at2g02390.3", "at2g02500.1", "at2g04845.1", "at2g18850.2", "at2g19770.1",
"at2g20270.1", "at2g22570.2", "at2g23610.1", "at2g25950.1", "at2g26060.1",
"at2g29730.1", "at2g30410.2", "at2g31670.1", "at2g32520.1", "at2g33740.1",
"at2g35410.1", "at2g41760.1", "at2g43100.1", "at2g48120.2", "at3g04780.1",
"at3g08010.1", "at3g10620.1", "at3g11210.1", "at3g15190.1", "at3g16450.3",
"at3g16990.1", "at3g17790.1", "at3g18420.1", "at3g19810.1", "at3g21760.1",
"at3g21790.1", "at3g23580.1", "at3g23600.2", "at3g25640.1", "at3g26450.1",
"at3g26900.3", "at3g27060.1", "at3g48700.1", "at3g50440.1", "at3g54900.1",
"at3g55040.1", "at3g56310.1", "at3g58470.1", "at3g60910.1", "at3g63250.2",
"at4g09040.2", "at4g14710.2", "at4g16690.1", "at4g26840.1", "at4g28030.2",
"at4g30550.1", "at4g31310.1", "at4g32930.1", "at4g33950.1", "at4g34090.1",
"at4g37020.1", "at4g37150.1", "at4g37470.1", "at4g38225.2", "at4g38800.1",
"at5g04740.1", "at5g08170.1", "at5g11330.1", "at5g11950.2", "at5g14910.1",
"at5g16440.1", "at5g19680.1", "at5g28830.1", "at5g32450.1", "at5g38480.1",
"at5g40280.1", "at5g41310.1", "at5g42980.1", "at5g43070.1", "at5g44600.1",
"at5g48480.1", "at5g53045.1", "at5g58240.2", "at5g58490.1", "at5g58590.1",
"at5g61500.1", "at5g62180.1"), class = "data.frame")
I can't dput whole tbl_cluster because it's too big...
You can achieve this with a simple for loop. The dynamic variable naming may require use of assign.
k=dim(tbl_cluster)
for(i in 1:k){
cluster <- tbl_cluster[tbl_cluster$fit.cluster == i,]
cluster <- cluster1[,-25]
cluster <- as.matrix(cluster[,2:24])
mode(cluster)<-"numeric"
heatmap.2(cluster,
Colv = NA,
scale = "none",
dendrogram = "row",
col=rainbow(256, s = 1, v = 1, start = 0, end = 2/6, alpha = 1),
density.info = "none",
trace = "none",
key = FALSE,
cexCol=0.5,
cexRow=1)
mtext(paste("Cluster ",i,"_"), side=3, line=-1, cex=2, col="black")
mtext("Size in kDa", side=1, line=3.5, cex=1.3, col="black")
## at this point you can dump the cluster object
}