I am having quite a bit of difficultly getting annotations to be in the correct spot. I want the first set the "Critical" in the middle of the bars that contain "Critical" and the "Somewhat Important" in the middle of that bar. I have tried changing the alignment I have looked at SO many different examples I am getting confused. I assume that it the add_annotation (x= ) that needs to be changed . The commented lines are things I have changed or tried with no success. Thanks for any input that can point me in the right direction without giving me the answer directly.
library(plotly)
levels <-c("Critical", "Somewhat_Important", "Not_Important")
y<-c("Predictive Maintenance", "Security", "Self organizing networks",
"Network Management", "Fraud Assurance", "Data Monetization", "CEM")
Predictive_Maintenance <-c(92, 8, 0)
Security <-c(75, 17, 8)
Self_organizing_networks <-c(67, 33, 0)
Network_Management <-c(58, 42, 0)
Fraud_revenue_assurance <-c(58, 42,0)
Data_Monetization <-c(42, 50, 8)
CEM <-c(42, 50, 8)
ML_Use_cases <-data.frame(rbind(
Predictive_Maintenance,
Security,
Self_organizing_networks,
Network_Management,
Fraud_revenue_assurance,
Data_Monetization,
CEM
)
)
colnames(ML_Use_cases)<-levels
ML_Use_cases$levels <- factor(ML_Use_cases$levels, levels = c("Critical", "Somewhat Important", "Not important"))
fig <- plot_ly(ML_Use_cases, x = ~Critical, y = ~y, type = 'bar', orientation = 'h', name = "Critical",
marker = list(color = 'rgba(216, 101, 34, 0.8)',
line = list(color = 'rgba(216, 101, 34, 0.8)',
width = 3)))
fig <- fig %>% add_trace(x = ~Somewhat_Important, name = "Somewhat Important",
marker = list(color = 'rgba(216, 131, 82, 0.8)',
line = list(color = 'rgba(216, 101, 34, 0.8)',
width = 3), textposition="auto"))
fig <- fig %>% add_trace(x = ~Not_Important, name = "Not important",
marker = list(color = 'rgba(216, 184, 166, 0.85)',
line = list(color = 'rgba(216, 101, 34, 0.8)',
width = 3), textposition="auto"))
fig <- fig %>% layout(barmode = 'stack',
xaxis = list(title = ""),
yaxis = list(title =""))
fig <- fig %>% add_annotations(xref = 'x', yref = 'y',
# x = Security, y = levels,
text = paste(ML_Use_cases[,"Critical"], '%'),
textposition ="inside left",
font = list(family = 'San Serif', size = 12,
color = 'rgb(248, 248, 255)', align="center"),
showarrow = FALSE)
#fig <- fig %>% add_annotations(xref = 'x', yref = 'y',
#x = Self_organizing_networks +Security, y = y,
# text = paste(ML_Use_cases[,"Somewhat_Important"], '%'),
# # textposition ="inside left",
# font = list(family = 'San Serif', size = 12,
# color = 'rgb(248, 248, 255)', align="left"),
# showarrow = FALSE)
fig%>% layout(paper_bgcolor='#3F3A38',plot_bgcolor='#3F3A38',
catagoryorder="ML_Use_Case",
font = list(
family = "San Serif",
color="#ffffff",
size=16
)
)
