How can I plot a step graph in R?
0
0
Entering edit mode
8 days ago

I want to plot a step graph or an inverse KM plot in R. Please help me to plot the graph with R scripts. I have attached a picture of plot which I want to make for my data exactly similar.

enter image description here

recurrence Step-graph Survival • 415 views
ADD COMMENT
1
Entering edit mode

Please, show us what you have tried so far to reach your goal and we can see how to improve it. The community is only here to provide guidance and submit inputs.

https://stackoverflow.com/questions/23463698/how-to-create-a-stair-step-plot-of-data-in-r-ggplot2

https://stats.stackexchange.com/questions/14620/how-to-plot-a-stair-steps-function-with-ggplot

ADD REPLY
0
Entering edit mode

I'm getting a plot like that with this code

library(openxlsx)
library(survival)
library(survminer)

data = read.xlsx("PQ_data.xlsx")

km_fit <- survfit(Surv(time, Status) ~ group, data = data)

p= ggsurvplot(km_fit, 
           data = data, 
           fun = "event",  # This specifies we want to plot the event probability (risk of recurrence)
           pval = TRUE,     # Show p-value for comparison between groups
           risk.table = TRUE, 
           conf.int = FALSE, 
           #palette = c("#E7B800", "#2E9FDF"),  # Custom colors for groups
           title = "Kaplan-Meier Curve for Risk of Recurrence",
           xlab = "Time (Weeks)", 
           ylab = "Risk of Recurrence",
           legend.title = "Group",
           #legend.labs = c("Group A", "Group B")
           )

jpeg("km_plot_risk_of_recurrence.jpg",height=15*350,width=25*350,res=800)
p
dev.off()

enter image description here

Please give inputs how can I improve this.

My input data is like so:

country        drug   dosage      group        time   Status
Afghanistan    PQ     0.25        very_low     52     1
Colombia       PQ     0.25        very_low     11     1
Vietnam        PQ     0.5         high         4      1
India          PQ     75          weekly       52     1
Brazil         PQ     0.5         high         26     1
China          PQ     0.45        low          4      1
India          PQ     75          weekly       52     1
Japan          PQ     210         weekly       12     1
ADD REPLY
0
Entering edit mode

What is the problem with this plot ?

ADD REPLY

Login before adding your answer.

Traffic: 2141 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6