Reputation: 1983
I am using plotly to decompose all the factor of an evolution, I want to graph a bar diagram and then to add the "sum" as a marker, this way :
libelle <- c("A","B","C","A","B","C")
value <- c(1500000,987000,1540000,-600000,-627000,-1240000)
type <- c("gain","gain","gain","loss","loss","loss")
data <- data.frame(libelle,value,annee)
plot_ly(data=data,x=value,y=libelle,group=type,type="bar",orientation="h") %>%
group_by(libelle) %>% summarise(sum = sum(value)) %>%
add_trace(x=sum,y=libelle,mode="markers",marker=list(color="black"),name="total")
All is fine with this graph, except for the hoverinfo : I would like to keep the hoverinfo of the first trace (when I over anywhere on a libelle, I get the info from both loss and gain), and with the second trace, it is replaced by another. I tried to put hoverinfo="none" in the add_trace, with no result.
any idea ?
Upvotes: 2
Views: 6076
Reputation: 19
Create a hovertemplate = paste("%{value} text <br>","text","<extra></extra>")
this <extra></extra>
, ends the trace.
Upvotes: 0
Reputation: 7153
You should be able to state which level you wanted the hover to appear by adding hoverinfo separately.
To show hover info for trace and not the bar plot:
plot_ly(data=data,x=value,y=libelle,group=type,type="bar",orientation="h", hoverinfo="none") %>%
group_by(libelle) %>% summarise(sum = sum(value)) %>%
add_trace(x=sum,y=libelle,mode="markers",marker=list(color="black"),name="total", hoverinfo="all")
To show hover info for bar and not the trace markers:
plot_ly(data=data,x=value,y=libelle,group=type,type="bar",orientation="h", hoverinfo="all") %>%
group_by(libelle) %>% summarise(sum = sum(value)) %>%
add_trace(x=sum,y=libelle,mode="markers",marker=list(color="black"),name="total", hoverinfo="none")
Upvotes: 2