-
I would like to add tick marks near the x-axis indicating deciles of the x-variable (so I can get an idea of where the distribution lies). Is it possible to do this with
suppressPackageStartupMessages(library(visreg));
suppressPackageStartupMessages(library(survival));
fit <- coxph(Surv(futime, fustat) ~ age + rx, data = ovarian) ;
visreg(fit, 'age', ylab='log(Hazard ratio)', type = 'contrast', rug = 1) Created on 2024-05-29 with reprex v2.0.2 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The The quantile idea is interesting, especially if you have a lot of observations and overplotting is a concern. There's no option to do this directly in visreg, but it's straightforward to add this yourself as an annotation: library(ggplot2)
library(visreg)
lm(price ~ carat + cut, diamonds) |> visreg('carat', rug=2) lm(price ~ carat + cut, diamonds) |> visreg('carat')
quantile(diamonds$carat, probs = seq(0.1, 0.9, 0.1)) |> rug() Created on 2024-05-30 with reprex v2.1.0 |
Beta Was this translation helpful? Give feedback.
The
rug
option is documented in?plot.visreg
. It places a tick at every observation. There's alsorug=2
, which places ticks on the top or bottom depending on whether the observation is above or below the prediction. I don't think it provides any meaningful information if you're already plotting the partial residuals, but if you're not, it provides a bit of a surrogate so that you can still see something about where the data is.The quantile idea is interesting, especially if you have a lot of observations and overplotting is a concern. There's no option to do this directly in visreg, but it's straightforward to add this yourself as an annotation: