Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(data.table)
- library(ggplot2)
- # raw data
- data <- data.table(x = c(2,8,5,10,3,10,4,9,1,7),
- y = c(5,5,4,4,3,3,2,2,1,1),
- line_type = c("dashed","dashed","dashed","dashed","dashed","dashed","solid","solid","solid","solid"))
- # ggplot2
- ggplot(data = data) +
- geom_line(aes(x = x, y = y, group = y, linetype = line_type)) +
- geom_vline(xintercept = 10) +
- labs(x = "month", y = "patient No.", title = "Follow-up from treatment") +
- scale_linetype_discrete(name ="Line",
- breaks = c("dashed", "solid"),
- labels = c("censored", "uncensored")) +
- scale_x_continuous(breaks = seq(0, 10),
- labels = c("", "Jan.", "Feb.", "Mar.", "Apr.", "May",
- "June", "July", "Aug.", "Sep.", "Oct.")) +
- annotate("text", x = 9.5, y = 5, label= "End of study", size = 3) +
- theme_classic() +
- theme(plot.title = element_text(hjust = 0.5))
- # basic
- par(mar=c(5.1, 4.1, 4.1, 8.1))
- with(data,
- plot(x, y, xlab = "month", ylab = "patient No.",
- main = "Follow-up from treatment",
- xlim = c(0,11), ylim = c(0,5),
- type = "n",
- axes = FALSE))
- for(each_y in unique(data$y)) {
- with(data[y == each_y],
- lines(x, y, lty = line_type))
- }
- abline(v=10)
- text(x = 9.5, y = 5, labels = "End of study", cex = 0.8)
- axis(side = 1,
- at = seq(1, 10),
- labels = c("Jan.", "Feb.", "Mar.", "Apr.", "May",
- "June", "July", "Aug.", "Sep.", "Oct."))
- axis(side = 2)
- box()
- # legend box
- legend("topright", inset = c(-0.35, 0), xpd = TRUE,
- cex = 0.8,
- legend = c("censored","uncensored"),
- lty = c("dashed", "solid"),
- title = "Line")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement