route217
asked on
Show the x and y values on hoover on line graph
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.
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
}
ASKER
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
many thanks for the feedback
Welcome, glad to assist!!
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