根据 y 轴值更改气泡图的背景颜色(在 R 中使用 Plotly)

问题描述 投票:0回答:0

我使用 Plotly 包在 R 中创建了一个气泡图。我想更改 y 轴上某些值的背景颜色。例如,在下图中,理想的颜色是 80-100 和 140-160。

enter image description here

library(plotly)

data <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/school_earnings.csv")

fig <- plot_ly(data, x = ~Women, y = ~Men, text = ~School, type = 'scatter', mode = 'markers', color = ~Gap, colors = 'Reds',
        marker = list(size = ~Gap, opacity = 0.5))
fig <- fig %>% layout(title = 'Gender Gap in Earnings per University',
         xaxis = list(showgrid = FALSE),
         yaxis = list(showgrid = FALSE))

fig

我希望背景颜色是这样的: enter image description here

我试过 paper_bgcolor,它似乎改变了图例区域的颜色而不是气泡的背景。反正有没有达到我想要的?

library(plotly)

data <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/school_earnings.csv")

fig <- plot_ly(data, x = ~Women, y = ~Men, text = ~School, type = 'scatter', mode = 'markers', color = ~Gap, colors = 'Reds',
        marker = list(size = ~Gap, opacity = 0.5))
fig <- fig %>% layout(title = 'Gender Gap in Earnings per University',
         xaxis = list(showgrid = FALSE),
         yaxis = list(showgrid = FALSE),paper_bgcolor = "black")

fig

enter image description here

非常感谢您的想法!

r plotly background-color bubble-chart
© www.soinside.com 2019 - 2024. All rights reserved.