Error adding annotation colours to pheatmap in R: “more elements supplied than there are to replace”
I am a relative R newbie and am having some issues trying to change the colour palette used for annotations in pheatmap.
I have created an annotated heatmap from the file Total_depth_avg_mag.txt using the following commands:
library(vegan)
library(gplots)
library(dplyr)
library('pheatmap')
library(RColorBrewer)
#Reads data into table, adds row names and deletes the first column
dat<-read.table("Total_depth_avg_mag.txt", header = T)
row.names(dat) <- dat$mag
dat <- dat[, -1]
# Produces annotation data_frame from input file
data_annot_2 <- read.table("Mag_annot_taxonomy.txt", header = T)
rownames(data_annot_2) = data_annot_2$mag
data_annot <- data_annot_2["Taxonomy"]
#Produces annotated heatmap
pheatmap(dat, cluster_cols = F, cluster_rows = F, fontsize_col = 10,
fontsize_row = 5, filename = "Mags_all_unclustered_tax.png", width =20,
height =30, border_color= NA, annotation_row = data_annot)
Which produces the following:
Heatmap_with_generic_colours
As there are quite a few (34) variables in my annotations some of them end up having the same colours so I would like to use my own palette. I used the following code to try to do this:
#Making a version of the "Greys" set from Rcolorbrewer containing 17 colours
coul = brewer.pal(9, "Greys")
coul = colorRampPalette(coul)(17)
#Producing a palette to feed into pheatmap. Contains 34 colours.
my_palette <- c(brewer.pal(9, "Reds")[c(6)], brewer.pal(9, "Greens")
[c(4,7)], brewer.pal(9, "Oranges")[c(4)], brewer.pal(9, "Blues")[c(3,5,7)],
brewer.pal(8, "Accent")[c(4)], brewer.pal(8, "Accent")[c(6)], brewer.pal(8,
"Accent")[c(7)], coul, brewer.pal(9, "Purples")[c(3,4,5,7)], brewer.pal(9,
"BuGn")[c(3,4)], brewer.pal(8, "Pastel2")[c(7)])
#Producing annotated heatmap with my_palette
pheatmap(dat, cluster_cols = F, cluster_rows = F, fontsize_col = 10,
fontsize_row = 5, filename = "Mags_all_unclustered_tax_col.png", width =20,
height =30, border_color= NA, annotation_row = data_annot,
annotation_colors = my_palette)
I then get the error "Error in annotation_colors[[names(annotation)[i]]] <- factor_colors[ind] : more elements supplied than there are to replace"
I'm not sure why this is as my_palette definitely has 34 colours in it and my annotation should contain 34 variables.
Can anyone suggest anything to fix this?
r pheatmap
add a comment |
I am a relative R newbie and am having some issues trying to change the colour palette used for annotations in pheatmap.
I have created an annotated heatmap from the file Total_depth_avg_mag.txt using the following commands:
library(vegan)
library(gplots)
library(dplyr)
library('pheatmap')
library(RColorBrewer)
#Reads data into table, adds row names and deletes the first column
dat<-read.table("Total_depth_avg_mag.txt", header = T)
row.names(dat) <- dat$mag
dat <- dat[, -1]
# Produces annotation data_frame from input file
data_annot_2 <- read.table("Mag_annot_taxonomy.txt", header = T)
rownames(data_annot_2) = data_annot_2$mag
data_annot <- data_annot_2["Taxonomy"]
#Produces annotated heatmap
pheatmap(dat, cluster_cols = F, cluster_rows = F, fontsize_col = 10,
fontsize_row = 5, filename = "Mags_all_unclustered_tax.png", width =20,
height =30, border_color= NA, annotation_row = data_annot)
Which produces the following:
Heatmap_with_generic_colours
As there are quite a few (34) variables in my annotations some of them end up having the same colours so I would like to use my own palette. I used the following code to try to do this:
#Making a version of the "Greys" set from Rcolorbrewer containing 17 colours
coul = brewer.pal(9, "Greys")
coul = colorRampPalette(coul)(17)
#Producing a palette to feed into pheatmap. Contains 34 colours.
my_palette <- c(brewer.pal(9, "Reds")[c(6)], brewer.pal(9, "Greens")
[c(4,7)], brewer.pal(9, "Oranges")[c(4)], brewer.pal(9, "Blues")[c(3,5,7)],
brewer.pal(8, "Accent")[c(4)], brewer.pal(8, "Accent")[c(6)], brewer.pal(8,
"Accent")[c(7)], coul, brewer.pal(9, "Purples")[c(3,4,5,7)], brewer.pal(9,
"BuGn")[c(3,4)], brewer.pal(8, "Pastel2")[c(7)])
#Producing annotated heatmap with my_palette
pheatmap(dat, cluster_cols = F, cluster_rows = F, fontsize_col = 10,
fontsize_row = 5, filename = "Mags_all_unclustered_tax_col.png", width =20,
height =30, border_color= NA, annotation_row = data_annot,
annotation_colors = my_palette)
I then get the error "Error in annotation_colors[[names(annotation)[i]]] <- factor_colors[ind] : more elements supplied than there are to replace"
I'm not sure why this is as my_palette definitely has 34 colours in it and my annotation should contain 34 variables.
Can anyone suggest anything to fix this?
r pheatmap
add a comment |
I am a relative R newbie and am having some issues trying to change the colour palette used for annotations in pheatmap.
I have created an annotated heatmap from the file Total_depth_avg_mag.txt using the following commands:
library(vegan)
library(gplots)
library(dplyr)
library('pheatmap')
library(RColorBrewer)
#Reads data into table, adds row names and deletes the first column
dat<-read.table("Total_depth_avg_mag.txt", header = T)
row.names(dat) <- dat$mag
dat <- dat[, -1]
# Produces annotation data_frame from input file
data_annot_2 <- read.table("Mag_annot_taxonomy.txt", header = T)
rownames(data_annot_2) = data_annot_2$mag
data_annot <- data_annot_2["Taxonomy"]
#Produces annotated heatmap
pheatmap(dat, cluster_cols = F, cluster_rows = F, fontsize_col = 10,
fontsize_row = 5, filename = "Mags_all_unclustered_tax.png", width =20,
height =30, border_color= NA, annotation_row = data_annot)
Which produces the following:
Heatmap_with_generic_colours
As there are quite a few (34) variables in my annotations some of them end up having the same colours so I would like to use my own palette. I used the following code to try to do this:
#Making a version of the "Greys" set from Rcolorbrewer containing 17 colours
coul = brewer.pal(9, "Greys")
coul = colorRampPalette(coul)(17)
#Producing a palette to feed into pheatmap. Contains 34 colours.
my_palette <- c(brewer.pal(9, "Reds")[c(6)], brewer.pal(9, "Greens")
[c(4,7)], brewer.pal(9, "Oranges")[c(4)], brewer.pal(9, "Blues")[c(3,5,7)],
brewer.pal(8, "Accent")[c(4)], brewer.pal(8, "Accent")[c(6)], brewer.pal(8,
"Accent")[c(7)], coul, brewer.pal(9, "Purples")[c(3,4,5,7)], brewer.pal(9,
"BuGn")[c(3,4)], brewer.pal(8, "Pastel2")[c(7)])
#Producing annotated heatmap with my_palette
pheatmap(dat, cluster_cols = F, cluster_rows = F, fontsize_col = 10,
fontsize_row = 5, filename = "Mags_all_unclustered_tax_col.png", width =20,
height =30, border_color= NA, annotation_row = data_annot,
annotation_colors = my_palette)
I then get the error "Error in annotation_colors[[names(annotation)[i]]] <- factor_colors[ind] : more elements supplied than there are to replace"
I'm not sure why this is as my_palette definitely has 34 colours in it and my annotation should contain 34 variables.
Can anyone suggest anything to fix this?
r pheatmap
I am a relative R newbie and am having some issues trying to change the colour palette used for annotations in pheatmap.
I have created an annotated heatmap from the file Total_depth_avg_mag.txt using the following commands:
library(vegan)
library(gplots)
library(dplyr)
library('pheatmap')
library(RColorBrewer)
#Reads data into table, adds row names and deletes the first column
dat<-read.table("Total_depth_avg_mag.txt", header = T)
row.names(dat) <- dat$mag
dat <- dat[, -1]
# Produces annotation data_frame from input file
data_annot_2 <- read.table("Mag_annot_taxonomy.txt", header = T)
rownames(data_annot_2) = data_annot_2$mag
data_annot <- data_annot_2["Taxonomy"]
#Produces annotated heatmap
pheatmap(dat, cluster_cols = F, cluster_rows = F, fontsize_col = 10,
fontsize_row = 5, filename = "Mags_all_unclustered_tax.png", width =20,
height =30, border_color= NA, annotation_row = data_annot)
Which produces the following:
Heatmap_with_generic_colours
As there are quite a few (34) variables in my annotations some of them end up having the same colours so I would like to use my own palette. I used the following code to try to do this:
#Making a version of the "Greys" set from Rcolorbrewer containing 17 colours
coul = brewer.pal(9, "Greys")
coul = colorRampPalette(coul)(17)
#Producing a palette to feed into pheatmap. Contains 34 colours.
my_palette <- c(brewer.pal(9, "Reds")[c(6)], brewer.pal(9, "Greens")
[c(4,7)], brewer.pal(9, "Oranges")[c(4)], brewer.pal(9, "Blues")[c(3,5,7)],
brewer.pal(8, "Accent")[c(4)], brewer.pal(8, "Accent")[c(6)], brewer.pal(8,
"Accent")[c(7)], coul, brewer.pal(9, "Purples")[c(3,4,5,7)], brewer.pal(9,
"BuGn")[c(3,4)], brewer.pal(8, "Pastel2")[c(7)])
#Producing annotated heatmap with my_palette
pheatmap(dat, cluster_cols = F, cluster_rows = F, fontsize_col = 10,
fontsize_row = 5, filename = "Mags_all_unclustered_tax_col.png", width =20,
height =30, border_color= NA, annotation_row = data_annot,
annotation_colors = my_palette)
I then get the error "Error in annotation_colors[[names(annotation)[i]]] <- factor_colors[ind] : more elements supplied than there are to replace"
I'm not sure why this is as my_palette definitely has 34 colours in it and my annotation should contain 34 variables.
Can anyone suggest anything to fix this?
r pheatmap
r pheatmap
asked Nov 23 '18 at 14:31
SomebodyatthedoorSomebodyatthedoor
11
11
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448559%2ferror-adding-annotation-colours-to-pheatmap-in-r-more-elements-supplied-than-t%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448559%2ferror-adding-annotation-colours-to-pheatmap-in-r-more-elements-supplied-than-t%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown