Black Lives Matter. Please consider donating to Black Girls Code today.

How to plot and present the multiple values whenever user placed mouse on point it using plotly and ggplot2

Hi ,

I have dataset (sample) something it’s looks like a below(or PFA) and here I have a requirement like this whenever user placed mouse on it, it needs display Ordernumber,OrderDate,Totalamount at this moment i’m getting only OrderDate and Totalamount as I have passed these 2 parameters to X and Y.Can anyone guide me how to do that .Here I’m attaching sample data as well R script that you can use it for to plot the graph .
Thanks in advance !!

Data :t5 <- data.frame(list(OrderNumber = c(1005,10010,10011,10012,10013,10028),OrderDate=c( “2015-05-28 10:13:19”, “2015-05-29 12:18:46”,“2015-06-01 05:18:06”,“2015-06-01 05:38:30”,“2015-06-01 05:44:13”,“2015-07-16 14:34:09”),TotalCost=c(44.9800,12.8993,38.0000,38.0000,9.5000,16.5743)))

R script :
g = ggplot(data = t5, aes(x = OrderDate, y = TotalCost)) +
geom_line(stat = “identity”,color=“blue”) +
geom_point() +
scale_fill_manual(name = “legend”) +
ylab(“Order Cost in $”) +
xlab(“OrderDate”) +



Hi Manohar,
Try passing aes(text=paste(“OrderNumber:”,Ordernumber,“OrderDate:”,OrderDate,“Totalamount:”,Totalamount)) into geom_point.


Oh…and you can use html line breaks with < br > (minus spaces) to insert line breaks. Having a hard time to demonstrate here since it keeps creating a line break in the editor…

aes(text=paste(“Ordernumber:”,Ordernumber**,"< br >OrderDate:",OrderDate,…ect.