addy
addy

Reputation: 113

Axes labels in plotly in R

Hi I the have following code in R plotly. I want to provide axes ticks for e.g. 0:10 for X-axis and seq(from=1000, to=4000, length.out=11) for Y-axis. Can you please help me with this ?

set.seed(0)

#Sample matrix
bitmap<-matrix(rnorm(150000,mean=1:500),nrow = 300, ncol = 500)

plot_ly(z=bitmap) %>% add_heatmap()

Upvotes: 1

Views: 3170

Answers (1)

Maximilian Peters
Maximilian Peters

Reputation: 31649

Are you looking for tickvals and ticktext?

library(plotly)
library(magrittr)
set.seed(0)

#Sample matrix
nrows <- 300
ncols <- 500
bitmap<-matrix(rnorm(150000 ,mean = 1:500),nrow = nrows, ncol = ncols)

plot_ly(z=bitmap) %>% 
  add_heatmap() %>% 
  layout(xaxis=list(tickvals = seq(from = 0, 
                                   to = ncols, 
                                   length.out = 10),
                    ticktext = c(0:9)),
         yaxis=list(tickvals = seq(from = 0,
                                   to = nrows,
                                   length.out = 11),
                    ticktext = seq(from = 1000, 
                                   to = 4000, 
                                   length.out = 11)
                    )
         )

enter image description here

Upvotes: 3

Related Questions