Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a superscript or a subscript to an axis label to a 3D plot in plotly?

Tags:

plot

r

plotly

How to add a superscript or a subscript to an axis label to a 3D plot in plotly?

I tried to use bquote, but it did not work. Googling did not bring much on the matter either.

Scavenged code:

library(plotly)
set.seed(123)

n <- 100
theta <- runif(n, 0, 2*pi)
u <- runif(n, -1, 1)


base<-'B1'
compare<-'A1'
plot (1, 1, main = bquote('Annual mean' ~CO[2] ~'Flux Difference: \n'  ~.(compare)~ 'minus'~.(base)))


p <- plot_ly(x = ~sqrt(1 - u^2) * cos(theta), y = ~sqrt(1 - u^2) * sin(theta), z = ~u) %>%
  layout(
    title = "Layout options in a 3d scatter plot",
    scene = list(
      xaxis = list(title = bquote('Annual mean' ~CO[2] ~'Flux Difference: \n'  ~.(compare)~ 'minus'~.(base))),
      yaxis = list(title = "Sin"),
      zaxis = list(title = "Z")
    ))
p

Thank you for your time!

like image 556
bud.dugong Avatar asked Jul 24 '17 13:07

bud.dugong


1 Answers

With HTML tags, for example:

yaxis = list(title = "Sin<sup>super</sup>")

More info here. Hope this helps!

enter image description here

like image 57
Florian Avatar answered Sep 20 '22 00:09

Florian