Reputation: 215
I'm trying to reproduce this plot I saw on a paper. The original author did it in excel or sigmaplot, he doesn't remember anymore.
Using a geom_area
won't produce exactly the same.
This is what I got so far:
a %>%
filter(p.value < 0.05) %>%
ggplot(., aes(x = time, y = p.value)) +
geom_area() +
scale_y_reverse()
But it does not look the same. I also tried geom_ribbon
and geom_bar
, but they look different. In the plot I want to replicate the data seems to be inversed, and I can't do that.
edit: oops forgot to link the data> here's a dput
https://pastebin.com/XWbb7zjt
Upvotes: 1
Views: 171
Reputation: 15072
I think you needed to look more carefully into what geom_area
actually does. It plots bars with the bottom at ymin = 0
and the top at ymax
, and is a special case of geom_ribbon
which allows freer setting of ymin
. This is the plot I think you want. Here we just tell ggplot
to plot the bars between the p value and 0.05, which with the scale reversed is at the bottom of the chart. This is based off your comment above that you wanted the negative space in your provided plot; I don't really know what makes this reversed plot more readable.
library(tidyverse)
plot_data <- tbl %>%
filter(p.value < 0.05)
ggplot(plot_data) +
theme_bw() +
geom_ribbon(aes(x = time, ymin = p.value, ymax = 0.05)) +
scale_y_reverse()
Upvotes: 1