Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is editing the panel.border not working inside ggplotly wrapper?

I have been working on a shiny app for some time, last week I updated all of my packages when I downloaded a new version of RStudio. All of a sudden, existing shiny themes will work outside of ggplotly but not within. I really just want the panel border to show up black but I can't add it as a theme element.

Ex This works and has a border

ggplot(mpg, aes(displ, hwy)) + 
geom_point() +
theme_bw()

This has no border...?

ggplotly(
ggplot(mpg, aes(displ, hwy)) + 
geom_point() +
theme_bw())

This also has no border

ggplotly(
ggplot(mpg, aes(displ, hwy)) + 
geom_point() +
theme_bw() +
  theme(panel.background = element_rect(fill = NULL, colour = "black")))

Any insight would be appreciated!

Edit: R Studio Version: 2025.09.0-387 ggplot2: 4.0.0 plotly: 4.11.0

like image 457
Rrrrrrr Avatar asked Nov 15 '25 15:11

Rrrrrrr


1 Answers

There has been a change. In ggplot2 version ‘3.5.2‘ & plotly version ‘4.11.0’

ggplotly(
  ggplot(mpg, aes(displ, hwy)) + 
   geom_point() +
   theme_bw()
)

produces this plot 3.5.2 If you want to roll back to this package version, you can do so like this:

remotes::install_version("ggplot2", version = "3.5.2", repos = "http://cran.us.r-project.org")

Here you have a list of mirrors for R.


whereas with the newer ggplot version ‘4.0.0.9000‘ the outer borders from panel.background are not translated to plotly

4.0.0 but we can manually bring them back using the layout for both axis

ggplotly(
  ggplot(mpg, aes(displ, hwy)) + 
    geom_point() +
    theme_bw()) |>
  layout(
    xaxis = list(showline = TRUE, linecolor = "black", linewidth = 0.66, mirror = TRUE),
    yaxis = list(showline = TRUE, linecolor = "black", linewidth = 0.66, mirror = TRUE)
  )

giving

4.0.0 fixed

like image 172
Tim G Avatar answered Nov 17 '25 07:11

Tim G



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!