ggseg / ggseg3d

ggseg3d R package for cisualising brain atlases through plotly
https://ggseg.github.io/ggseg3d/
Other
27 stars 9 forks source link

colorbar title instead of "z" #4

Closed ccjake closed 3 years ago

ccjake commented 4 years ago

I would like to change the title of the right side colorbar, but layout method in plotly failed.

drmowinckels commented 4 years ago

could you please provide the code that is not working so we can look into it?

ccjake commented 4 years ago

Hallo,

Thanks for reply. I took a closer look at the source code. You are using add_trace to create the colorbar instead of using the coloraxis or something come with plotly, so I think that's the reason, why the layout did not work. I have changed a little code in the source code and now it works.

p <- ggseg3d(.data = example1Data,
             atlas = desterieux_neu,
             colour = "wert", text = "beschreibung",
             surface = "LCBC",
             palette = c("red" = 1, "yellow" = 2, "blue" = 3),
             hemisphere = c("left","right"),
             show.legend = FALSE) 

 %>% layout(coloraxis=list(colorbar=list(title=list(text="not work"))))

The above code cannot change the title.

p <- ggseg3d(.data = example1Data,  
             atlas = desterieux_neu,
             colour = "wert", text = "beschreibung",
             surface = "LCBC",
             palette = c("red" = 1, "yellow" = 2, "blue" = 3),
             hemisphere = c("left","right"),
             show.legend = FALSE)
f <- get_farbe(c("red" = 1, "yellow" = 2, "blue" = 3))
dt_leg <- dplyr::mutate(f, x = 0, y = 0, z = 0)
p = plotly::add_trace(p, data = dt_leg, x = ~x, y = ~y,
                      z = ~z, intensity = ~values,
                      colorscale = unname(dt_leg[,c("norm", "hex")]),
                      colorbar=list(title=list(text="mm")), type = "mesh3d")

The second piece of code can chang the title rightly, they are basically the code in "ggseg3d()" . Maybe it's not the best way, but it works on me.

Best wishes.

drmowinckels commented 4 years ago

Hey!

Thanks for digging into the code and finding the culprit, and also providing a solution.

I have now added an argument where you can control the colourbar in the add_trace for the colourbar. It's in commit 5fc8fbf52aa.

Check that out and see if that behaves more like you expect :)

ccjake commented 4 years ago

Hallo,

Yes, it works perfectly. Thanks for update!