Hi community, Im want to do a bar plot with plotly
but some bars are drawing different about the data.
data_plotly <- structure(list(ESTRUCTURA = c("CASA 1", "CASA 1", "CASA 2", "CASA 2",
"CASA 3", "CASA 3", "CASA 4", "CASA 4", "CASA 5", "CASA 5", "CASA 6",
"CASA 6", "CASA 7", "CASA 7"), OCUPACION_CASA = c(49, 49, 28,
28, 1, 1, 0, 0, 29, 29, 37, 37, 18, 18), TOTAL_DISPONIBLES = c(50,
50, 58, 58, 44, 44, 44, 44, 30, 30, 41, 41, 22, 22), name = c("OCUPACION",
"DISPONIBLES", "OCUPACION", "DISPONIBLES", "OCUPACION", "DISPONIBLES",
"OCUPACION", "DISPONIBLES", "OCUPACION", "DISPONIBLES", "OCUPACION",
"DISPONIBLES", "OCUPACION", "DISPONIBLES"), value = c(1, 50,
30, 58, 43, 44, 44, 44, 1, 30, 4, 41, 4, 22), PERC_OCUPACION = c(2,
98, 51.72, 48.28, 97.73, 2.27, 100, 0, 3.33, 96.67, 9.76, 90.24,
18.18, 81.82)), row.names = c(NA, -14L), class = c("tbl_df",
"tbl", "data.frame"))
# plotly
plot_ly(data_plotly,
x = ~fct_reorder(ESTRUCTURA, -value),
y = ~value,
type = 'bar',
color = ~name,
colors = c("DISPONIBLES" = "#4CAF50",
"OCUPACION" = "#F44336"),
text = ~paste(name, ": ", PERC_OCUPACION, '%'),
textposition = 'outside') |>
layout(
title = "Porcentaje de ocupación según cada Casa en Carrizal",
xaxis = list(title = "CASA"),
yaxis = list(title = "Cantidad de espacios"),
barmode = 'stack',
legend = list(title = list(text = "")),
annotations = list(
list(
text = "Fuente: ORACLE",
xref = "paper",
yref = "paper",
x = 1,
y = -0.2,
showarrow = FALSE,
font = list(size = 12)
)
)
)
For example in CASA 4 and CASA 3, the plot is wrong. the bars are not overlapped.
I dont not why is wrong for a few bars but for others is well
Tnks for any solutions.