Show the x and y values on hoover on line graph

route217
route217 used Ask the Experts™
on
Hi Experts

I am new to R Script and coding, just inherited some R Code that i which plots perfectly fine and gives the correct results. I want to have the ability to show the x and y values when a user hoovers the mouse cursor over the line.

I have found a link to a articles that describe how to carry out the necessary step but having no luck at all..
[url=" https://www.r-graph-gallery.com/124-change-hover-text-in-plotly/"]


my r code.
library(dplyr)
library(ggplot2)
library(survival)
library(survminer)
library(grid)
library(gridExtra)
library(plotly)
pc <- dataset
fstat <- pc %>% mutate(fstatus = case_when(OUTCOMETYPE=="Revised" ~ 1,TRUE ~ 0))
pmpa <- fstat %>% select(PRIMARYPROCEDUREID,PRIMARYTOOUTCOMEYEARS,fstatus,OUTCOMETYPE)
if(nrow(pmpa) < 4){
d <- pmpa %>% select(PRIMARYPROCEDUREID,PRIMARYTOOUTCOMEYEARS,OUTCOMETYPE) %>% mutate(INSUFFICIENTDATA = "Summary Results")
h = head(d[,2:4])
grid.table(h)
}else{
fit <- survfit(Surv(PRIMARYTOOUTCOMEYEARS,fstatus)~1,data = pmpa) 
ggsurv <- ggsurvplot(fit,
           ylab="Patient Analysis",
           xlab="Time (Years)",
           break.time.by = 1,
           xlim = c(0,max(fit$time)),
           surv.scale = "percent",
           legend.title = "Kaplan-Meier",
           legend.labs = "",
           risk.table = TRUE,
           fontsize = 3,
           font.tickslab = c(10, "plain"),
           risk.table.y.text = FALSE,
           fun = "event"
           )
ggsurv$plot <- ggsurv$plot + theme(plot.title = element_text(hjust = 0.5, size=18), panel.grid.major = element_line(colour ="grey90"))
ggsurv$table <- ggsurv$table + theme(plot.title = element_text(hjust = 0.5, size = 10))

ggsurv     
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Raja Jegan RSQL Server DBA & Architect, EE Solution Guide
Awarded 2009
Distinguished Expert 2018

Commented:
I have studied R long time back but not using it right now..
Kindly try this below function which I used long time back and it should meet your requirements.
https://shiny.rstudio.com/articles/plot-interaction.html
route217Junior

Author

Commented:
Hi Experts

No sure that helps , kindly have a look at my link i posted that is the kind of answer i was looking for. Does Experts exchange provide support for the R, R Studio community?
SQL Server DBA & Architect, EE Solution Guide
Awarded 2009
Distinguished Expert 2018
Commented:
Okay, with my basic R skills I hope I'm responding correctly..
plotly shown in the link seems like a third party function, kindly confirm whether you have created the function or module correctly in your environment..
That's why I've recommended to use the free version of text hovering with the one I tried long time back..
To properly install shiny library which I've referred, kindly follow the below link..
https://www.r-project.org/nosvn/pandoc/shiny.html
route217Junior

Author

Commented:
many thanks for the feedback
Raja Jegan RSQL Server DBA & Architect, EE Solution Guide
Awarded 2009
Distinguished Expert 2018

Commented:
Welcome, glad to assist!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial