6

I've been trying to change the size of the labels on my x and y axes of a graph drawn using plot_ly in R.

Below is my code:

q <- plot_ly(
    x=colnames(avg_exp_norm),
    y=row.names(avg_exp_norm),
    z = avg_exp_norm, type = "heatmap") %>% 
    layout(xaxis = list(size = 15), yaxis = list(size = 5))
q

But it doesn't work and in the result I don't see any changes in font size.

What I'm doing wrong and how can I fix it?

nyedidikeke
  • 6,899
  • 7
  • 44
  • 59
Sadegh Davoudi
  • 95
  • 1
  • 1
  • 6

1 Answers1

9

You need to specify the font size inside a nested list.

Here is a minimal reproducible example

library(plotly)
set.seed(2017)
x <- seq(1:10)
y <- x + rnorm(10)
plot_ly(
    x = ~x,
    y = ~y + rnorm(10)) %>%
    layout(
        xaxis = list(tickfont = list(size = 15)), 
        yaxis = list(tickfont = list(size = 5)))

enter image description here

See here for more options on how to modify/theme your axes.

If you want to change both axes labels and titles, you can use e.g. xaxis = list(titlefont = list(size = 5), tickfont = list(size = 5)).

Maurits Evers
  • 49,617
  • 4
  • 47
  • 68