R中的轴标签

时间:2017-04-10 05:38:17

标签: r graphics plotly

嗨我在R中有以下代码。 我想提供例如轴刻度X轴为0:10,Y轴为seq(from=1000, to=4000, length.out=11)。你能帮帮我吗?

set.seed(0)

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

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

1 个答案:

答案 0 :(得分:3)

您是否在寻找tickvalsticktext

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