Help with Type of ridge plot

Hey everyone,

I'm trying to plot some results of a bootstrap, but I'm having trouble doing it in the way a collaborator asked. It is essentially a ridge plot but instead of density or histograms, it just shows a line segment, with the inner 95% a bit thicker, and the outer 5% a bit smaller. With a red dot indicating the value we overserved for our data.
I have included a drawing of what it should look like. And some code that reproduces the information that I have;
A dataframe with bootstrapped samples for 4 coefficients,
A vector of observed coefficients

Hope someone here can point me in the right direction!

df <- data.frame(b0 = rnorm(50),
                 b1 = rnorm(50, 1),
                 b2 = rnorm(50, 0.75, 0.3),
                 b3 = rnorm(50, 2.75, .25))

observed <- c("b0" = 0.15, "b1" = 0.79, "b2" = 0.76, "b3" = 2.71)

reprex::reprex()
#> No input provided and clipboard is not available.
#> Rendering reprex...

Created on 2021-02-11 by the reprex package (v0.3.0)

Hi @cmues,
If I understand correctly, you need horizontal customized boxplots.
This should get you pretty close:

library(tidyverse)
df <- data.frame(b0 = rnorm(50),
                 b1 = rnorm(50, 1),
                 b2 = rnorm(50, 0.75, 0.3),
                 b3 = rnorm(50, 2.75, .25))
df_long <- pivot_longer(df, cols=1:4)

observed <- data.frame(b0 = 0.15, b1 = 0.79, b2 = 0.76, b3 = 2.71)
observed_long <- pivot_longer(observed, cols=1:4)

# Get the calculated 'boxplot' statistics
b1 <- boxplot(value ~ name, data=df_long, stats=keep)

keep <- as.data.frame(b1$stats)
names(keep) <- names(df)
keep$position <- c("lower_whisker", "lower_hinge", "median",
                   "upper_hinge", "upper_whisker")

keep_long <- pivot_longer(keep, cols=1:4)
keep_wide <- pivot_wider(keep_long, names_from=position, values_from=value)

ggplot(data=keep_wide) +
  geom_segment(aes(y=name, yend=name, x=lower_whisker, xend=upper_whisker), 
               colour="grey80", size=2) +
  geom_segment(aes(y=name, yend=name, x=lower_hinge, xend=upper_hinge),
                              colour="blue", size=5) +
  geom_point(data=observed_long, aes(y=name, x=value), col="red", size=2) +
  labs(x="Value", y="Coefficient") +
  theme_bw()

Created on 2021-02-13 by the reprex package (v1.0.0)

HTH

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.