Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plotly heatmap doesn't take a dataframe #329

Open
ziyadsaeed opened this issue Dec 7, 2015 · 4 comments
Open

plotly heatmap doesn't take a dataframe #329

ziyadsaeed opened this issue Dec 7, 2015 · 4 comments

Comments

@ziyadsaeed
Copy link

The figure reference documentation says

plot_ly(df, type="heatmap"[, ...])

the df in the code above indicates a data frame
The code below doesn't work

url <- "http://datasets.flowingdata.com/ppg2008.csv"
nba_players <- read.csv(url, row.names = 1)

plot_ly(nba_players, type = "heatmap")

A solution is to use a data.matrix

plot_ly(z = data.matrix(nba_players), 
           x = colnames(nba_players), 
           y = row.names(nba_players), 
           type = "heatmap")
@ziyadsaeed
Copy link
Author

what then is the syntax to use a dataframe without converting it to a matrix
Also Is there a way to tell it that the integer column x is the x label and integer column y is the y label and z values integer column z of the dataframe

@cpsievert
Copy link
Collaborator

I don't think it is currently possible to make a heatmap from a data frame. This will go on the todo list, but it isn't a super high priority right now.

PS. you can adds axis titles like so:

plot_ly(z = volcano, type = "heatmap") %>% layout(xaxis = list(title = "x"), yaxis = list(title = "y"))

@ziyadsaeed
Copy link
Author

for the time being this part of the heatmap documentation should be changed. Atleast it should mention that dataframe support is in the works

y (dataframe column, list, vector)
Sets the y coordinates.
x (dataframe column, list, vector)
Sets the x coordinates.
z (dataframe column, list, vector)
Sets the z data.

@simonegabbriellini
Copy link

@ziyadsaeed are you sure about your data.matrix solution? if I run your code, I get:

 plot_ly(z = data.matrix(nba_players), 
+         x = colnames(nba_players), 
+         y = row.names(nba_players), 
+         type = "heatmap")
Error: Variables must be length 1 or 50. 
Problem variables: 'x'

Looks like the axes should have same length, otherwise it complains... I don't understand why though...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants