I have the following code producing a scatter plot (using plotly in r)and I would like to add the legend representing the size of the markers totalValue
(it is a continuous variable representing the value of specific buildings), how could I do that?
f <- list(
family = "Courier New, monospace",
size = 18,
color = "#7f7f7f"
)
x <- list(
title = "Age of Buildings",
titlefont = f,
zeroline = FALSE,
showline = FALSE,
showticklabels = TRUE,
showgrid = TRUE
)
y <- list(
title = "Total Violations",
titlefont = f,
zeroline = FALSE,
showline = FALSE,
showticklabels = TRUE,
showgrid = TRUE
)
fig2 <- plot_ly(final, x=~agebuilding, y=~violationstotal, mode= "markers", color =
~INdexrehabless6, size = ~totalvalue)
fig2 <- fig2 %>% layout(xaxis = x, yaxis = y, legend=list(title=list(text='<b>
Housing Conditions </b>'))) #chaging name legend
fig2
sample of dataset:
agebuilding violationstotal INdexrehabless6 totalvalue
32 5 0 350000
120 15 1 50000
100 25 1 100000
32 31 0 210000
33 9 0 150000
50 20 0 301000
15 28 0 175000
70 18 1 125000
Here is the plot I get