Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add a greek letter to an axis label to a 3D plot in plotly?

I have below plot using plotly

library(plotly)
set.seed(1)
n <- 100
theta <- runif(n, 0, 2*pi)
u <- runif(n, -1, 1)


base<-'B1'
compare<-'A1'

p <- plot_ly(x = ~sqrt(1 - u^2) * cos(theta), y = ~sqrt(1 - u^2) * sin(theta), z = ~u) %>%
  layout(
    title = "Some plot",
    scene = list(
      yaxis = list(title = expression('theta'))
    ))
p

I wanted to add greek expression theta in the y-axis title, and tried using expression(theta), however it is not rendering.

Could you please find how is it possible to add greek letters in plotly?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

One option would be to use UTF-8 codes, e.g. "\u03B8" for a theta

library(plotly)
set.seed(1)

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

base<-'B1'
compare<-'A1'

p <- plot_ly(x = ~sqrt(1 - u^2) * cos(theta), y = ~sqrt(1 - u^2) * sin(theta), z = ~u) %>%
  layout(
    title = "Some plot",
    scene = list(
      xaxis = list(title = list(text = "\u03B8")),
      yaxis = list(title = "Y-axis")
    ))
p

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading