R: Error in heatmap(data) : 'x' must be a numeric matrix. Which 'x' is it referring to?
I am trying to create a heatmap in R. This is my dataset:
Team, Att_L, Att_M, Att_R,
Aston Villa, 0.37, 0.24, 0.39
Birmingham City, 0.34, 0.26, 0.4
Blackburn Rovers, 0.38, 0.26, 0.36
Bolton Wanderers, 0.32, 0.27, 0.41
Brentford, 0.34, 0.28, 0.38
Bristol City, 0.37, 0.26, 0.37
Derby County, 0.34, 0.26, 0.4
Hull City, 0.38, 0.21, 0.41
Ipswich Town, 0.33, 0.24, 0.43
Leeds United, 0.37, 0.24, 0.39
Middlesbrough, 0.37, 0.25, 0.38
Millwall, 0.3, 0.24, 0.46
Norwich City, 0.36, 0.24, 0.4
Nottingham Forest, 0.37, 0.22, 0.41
Preston North End, 0.35, 0.26, 0.39
Queens Park Rangers, 0.35, 0.24, 0.41
Reading, 0.37, 0.23, 0.4
Rotherham United, 0.38, 0.27, 0.35
Sheffield United, 0.41, 0.21, 0.38
Sheffield Wednesday, 0.37, 0.29, 0.34
Stoke City, 0.36, 0.25, 0.39
Swansea City, 0.38, 0.24, 0.38
West Bromwich Albion, 0.38, 0.25, 0.37
Wigan Athletic, 0.38, 0.24, 0.38
It starts off as a tibble called Pitch_axis. I convert this to a table and use gather()
to get the data ready for the heatmap.
data2 <- as.data.table(gather(Pitch_axis, variable, value, Att_L:Att_R))
Then I try to run heatmap() on it:
heatmap(data2)
This returns the error:
>Error in heatmap(data2) : 'x' must be a numeric matrix
I don't understand this from two directions: 1. I don't understand which variable is 'x' 2. I tried converting to a matrix and all the observations came out in double "", so presumably as strings.
Any ideas how to fix this?
r
add a comment |
I am trying to create a heatmap in R. This is my dataset:
Team, Att_L, Att_M, Att_R,
Aston Villa, 0.37, 0.24, 0.39
Birmingham City, 0.34, 0.26, 0.4
Blackburn Rovers, 0.38, 0.26, 0.36
Bolton Wanderers, 0.32, 0.27, 0.41
Brentford, 0.34, 0.28, 0.38
Bristol City, 0.37, 0.26, 0.37
Derby County, 0.34, 0.26, 0.4
Hull City, 0.38, 0.21, 0.41
Ipswich Town, 0.33, 0.24, 0.43
Leeds United, 0.37, 0.24, 0.39
Middlesbrough, 0.37, 0.25, 0.38
Millwall, 0.3, 0.24, 0.46
Norwich City, 0.36, 0.24, 0.4
Nottingham Forest, 0.37, 0.22, 0.41
Preston North End, 0.35, 0.26, 0.39
Queens Park Rangers, 0.35, 0.24, 0.41
Reading, 0.37, 0.23, 0.4
Rotherham United, 0.38, 0.27, 0.35
Sheffield United, 0.41, 0.21, 0.38
Sheffield Wednesday, 0.37, 0.29, 0.34
Stoke City, 0.36, 0.25, 0.39
Swansea City, 0.38, 0.24, 0.38
West Bromwich Albion, 0.38, 0.25, 0.37
Wigan Athletic, 0.38, 0.24, 0.38
It starts off as a tibble called Pitch_axis. I convert this to a table and use gather()
to get the data ready for the heatmap.
data2 <- as.data.table(gather(Pitch_axis, variable, value, Att_L:Att_R))
Then I try to run heatmap() on it:
heatmap(data2)
This returns the error:
>Error in heatmap(data2) : 'x' must be a numeric matrix
I don't understand this from two directions: 1. I don't understand which variable is 'x' 2. I tried converting to a matrix and all the observations came out in double "", so presumably as strings.
Any ideas how to fix this?
r
1
For the error message, see?heatmap
and take a look at the first argument of the function. And for the second question: A matrix can only contain variables of a single type. Trymatrix(c(1, 2, "C"), 1)
and you'll see the first two elements will be coerced to characters, just like in your case (because of the Team column).
– markus
Jan 19 at 12:07
add a comment |
I am trying to create a heatmap in R. This is my dataset:
Team, Att_L, Att_M, Att_R,
Aston Villa, 0.37, 0.24, 0.39
Birmingham City, 0.34, 0.26, 0.4
Blackburn Rovers, 0.38, 0.26, 0.36
Bolton Wanderers, 0.32, 0.27, 0.41
Brentford, 0.34, 0.28, 0.38
Bristol City, 0.37, 0.26, 0.37
Derby County, 0.34, 0.26, 0.4
Hull City, 0.38, 0.21, 0.41
Ipswich Town, 0.33, 0.24, 0.43
Leeds United, 0.37, 0.24, 0.39
Middlesbrough, 0.37, 0.25, 0.38
Millwall, 0.3, 0.24, 0.46
Norwich City, 0.36, 0.24, 0.4
Nottingham Forest, 0.37, 0.22, 0.41
Preston North End, 0.35, 0.26, 0.39
Queens Park Rangers, 0.35, 0.24, 0.41
Reading, 0.37, 0.23, 0.4
Rotherham United, 0.38, 0.27, 0.35
Sheffield United, 0.41, 0.21, 0.38
Sheffield Wednesday, 0.37, 0.29, 0.34
Stoke City, 0.36, 0.25, 0.39
Swansea City, 0.38, 0.24, 0.38
West Bromwich Albion, 0.38, 0.25, 0.37
Wigan Athletic, 0.38, 0.24, 0.38
It starts off as a tibble called Pitch_axis. I convert this to a table and use gather()
to get the data ready for the heatmap.
data2 <- as.data.table(gather(Pitch_axis, variable, value, Att_L:Att_R))
Then I try to run heatmap() on it:
heatmap(data2)
This returns the error:
>Error in heatmap(data2) : 'x' must be a numeric matrix
I don't understand this from two directions: 1. I don't understand which variable is 'x' 2. I tried converting to a matrix and all the observations came out in double "", so presumably as strings.
Any ideas how to fix this?
r
I am trying to create a heatmap in R. This is my dataset:
Team, Att_L, Att_M, Att_R,
Aston Villa, 0.37, 0.24, 0.39
Birmingham City, 0.34, 0.26, 0.4
Blackburn Rovers, 0.38, 0.26, 0.36
Bolton Wanderers, 0.32, 0.27, 0.41
Brentford, 0.34, 0.28, 0.38
Bristol City, 0.37, 0.26, 0.37
Derby County, 0.34, 0.26, 0.4
Hull City, 0.38, 0.21, 0.41
Ipswich Town, 0.33, 0.24, 0.43
Leeds United, 0.37, 0.24, 0.39
Middlesbrough, 0.37, 0.25, 0.38
Millwall, 0.3, 0.24, 0.46
Norwich City, 0.36, 0.24, 0.4
Nottingham Forest, 0.37, 0.22, 0.41
Preston North End, 0.35, 0.26, 0.39
Queens Park Rangers, 0.35, 0.24, 0.41
Reading, 0.37, 0.23, 0.4
Rotherham United, 0.38, 0.27, 0.35
Sheffield United, 0.41, 0.21, 0.38
Sheffield Wednesday, 0.37, 0.29, 0.34
Stoke City, 0.36, 0.25, 0.39
Swansea City, 0.38, 0.24, 0.38
West Bromwich Albion, 0.38, 0.25, 0.37
Wigan Athletic, 0.38, 0.24, 0.38
It starts off as a tibble called Pitch_axis. I convert this to a table and use gather()
to get the data ready for the heatmap.
data2 <- as.data.table(gather(Pitch_axis, variable, value, Att_L:Att_R))
Then I try to run heatmap() on it:
heatmap(data2)
This returns the error:
>Error in heatmap(data2) : 'x' must be a numeric matrix
I don't understand this from two directions: 1. I don't understand which variable is 'x' 2. I tried converting to a matrix and all the observations came out in double "", so presumably as strings.
Any ideas how to fix this?
r
r
edited Jan 19 at 12:58
NelsonGon
2,2661625
2,2661625
asked Jan 19 at 11:55
Mr_Percy_HeatMr_Percy_Heat
13
13
1
For the error message, see?heatmap
and take a look at the first argument of the function. And for the second question: A matrix can only contain variables of a single type. Trymatrix(c(1, 2, "C"), 1)
and you'll see the first two elements will be coerced to characters, just like in your case (because of the Team column).
– markus
Jan 19 at 12:07
add a comment |
1
For the error message, see?heatmap
and take a look at the first argument of the function. And for the second question: A matrix can only contain variables of a single type. Trymatrix(c(1, 2, "C"), 1)
and you'll see the first two elements will be coerced to characters, just like in your case (because of the Team column).
– markus
Jan 19 at 12:07
1
1
For the error message, see
?heatmap
and take a look at the first argument of the function. And for the second question: A matrix can only contain variables of a single type. Try matrix(c(1, 2, "C"), 1)
and you'll see the first two elements will be coerced to characters, just like in your case (because of the Team column).– markus
Jan 19 at 12:07
For the error message, see
?heatmap
and take a look at the first argument of the function. And for the second question: A matrix can only contain variables of a single type. Try matrix(c(1, 2, "C"), 1)
and you'll see the first two elements will be coerced to characters, just like in your case (because of the Team column).– markus
Jan 19 at 12:07
add a comment |
2 Answers
2
active
oldest
votes
Try this? Solely representative!
library(tidyverse)
df<-as.tibble(df)
df<-df %>%
gather("id","value",2:ncol(.))
df2<-matrix(df$value,4,8)
heatmap(df2,labRow=df$Team,labCol = df$id)
add a comment |
I eventually got this.
ggplot(data2, aes(Team, variable)) +
geom_tile(aes(fill = value), color = "white") +
scale_fill_gradient(low = "yellow", high = "red") +
ylab("") +
xlab("") +
theme(legend.title = element_text(size = 10),
legend.text = element_text(size = 12),
plot.title = element_text(size=16),
axis.title=element_text(size=14,face="bold"),
axis.text.x = element_text(angle = 90, hjust = 1)) +
ggtitle("Attack more down left, right or centre?",
subtitle = "") +
labs(fill = "%age") +
coord_flip()
add a comment |
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%2f54266813%2fr-error-in-heatmapdata-x-must-be-a-numeric-matrix-which-x-is-it-referr%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try this? Solely representative!
library(tidyverse)
df<-as.tibble(df)
df<-df %>%
gather("id","value",2:ncol(.))
df2<-matrix(df$value,4,8)
heatmap(df2,labRow=df$Team,labCol = df$id)
add a comment |
Try this? Solely representative!
library(tidyverse)
df<-as.tibble(df)
df<-df %>%
gather("id","value",2:ncol(.))
df2<-matrix(df$value,4,8)
heatmap(df2,labRow=df$Team,labCol = df$id)
add a comment |
Try this? Solely representative!
library(tidyverse)
df<-as.tibble(df)
df<-df %>%
gather("id","value",2:ncol(.))
df2<-matrix(df$value,4,8)
heatmap(df2,labRow=df$Team,labCol = df$id)
Try this? Solely representative!
library(tidyverse)
df<-as.tibble(df)
df<-df %>%
gather("id","value",2:ncol(.))
df2<-matrix(df$value,4,8)
heatmap(df2,labRow=df$Team,labCol = df$id)
answered Jan 19 at 12:05
NelsonGonNelsonGon
2,2661625
2,2661625
add a comment |
add a comment |
I eventually got this.
ggplot(data2, aes(Team, variable)) +
geom_tile(aes(fill = value), color = "white") +
scale_fill_gradient(low = "yellow", high = "red") +
ylab("") +
xlab("") +
theme(legend.title = element_text(size = 10),
legend.text = element_text(size = 12),
plot.title = element_text(size=16),
axis.title=element_text(size=14,face="bold"),
axis.text.x = element_text(angle = 90, hjust = 1)) +
ggtitle("Attack more down left, right or centre?",
subtitle = "") +
labs(fill = "%age") +
coord_flip()
add a comment |
I eventually got this.
ggplot(data2, aes(Team, variable)) +
geom_tile(aes(fill = value), color = "white") +
scale_fill_gradient(low = "yellow", high = "red") +
ylab("") +
xlab("") +
theme(legend.title = element_text(size = 10),
legend.text = element_text(size = 12),
plot.title = element_text(size=16),
axis.title=element_text(size=14,face="bold"),
axis.text.x = element_text(angle = 90, hjust = 1)) +
ggtitle("Attack more down left, right or centre?",
subtitle = "") +
labs(fill = "%age") +
coord_flip()
add a comment |
I eventually got this.
ggplot(data2, aes(Team, variable)) +
geom_tile(aes(fill = value), color = "white") +
scale_fill_gradient(low = "yellow", high = "red") +
ylab("") +
xlab("") +
theme(legend.title = element_text(size = 10),
legend.text = element_text(size = 12),
plot.title = element_text(size=16),
axis.title=element_text(size=14,face="bold"),
axis.text.x = element_text(angle = 90, hjust = 1)) +
ggtitle("Attack more down left, right or centre?",
subtitle = "") +
labs(fill = "%age") +
coord_flip()
I eventually got this.
ggplot(data2, aes(Team, variable)) +
geom_tile(aes(fill = value), color = "white") +
scale_fill_gradient(low = "yellow", high = "red") +
ylab("") +
xlab("") +
theme(legend.title = element_text(size = 10),
legend.text = element_text(size = 12),
plot.title = element_text(size=16),
axis.title=element_text(size=14,face="bold"),
axis.text.x = element_text(angle = 90, hjust = 1)) +
ggtitle("Attack more down left, right or centre?",
subtitle = "") +
labs(fill = "%age") +
coord_flip()
answered Jan 23 at 13:01
Mr_Percy_HeatMr_Percy_Heat
13
13
add a comment |
add a comment |
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%2f54266813%2fr-error-in-heatmapdata-x-must-be-a-numeric-matrix-which-x-is-it-referr%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
1
For the error message, see
?heatmap
and take a look at the first argument of the function. And for the second question: A matrix can only contain variables of a single type. Trymatrix(c(1, 2, "C"), 1)
and you'll see the first two elements will be coerced to characters, just like in your case (because of the Team column).– markus
Jan 19 at 12:07