I am attempting to plot p-values on a plot, and there are some instances where the p-value is either close to 0 or close to 1 (in the example below, I just coded these as 0 or 1 for illustrative purposes).
Given that they are in the edges of the plot, only half of the geom_point shows up, which is undesirable. Ideally, the other half of the shapes would show over the border, where the edges are at 1 and 0. I understand that one potential solution would be to change/remove the breaks() option, but I am wary of how it might leave space but also the border to the left (or right) that would not easily convey to people that the p-value is either between 0 and 1.
Here is the code:
library(dplyr)
library(ggplot2)
df <- data_frame(outcome = c("Outcome 1","Outcome 2", "Outcome 3", "Outcome 1","Outcome 2", "Outcome 3", "Outcome 1","Outcome 2", "Outcome 3"),
sample = c("Indiana", "Indiana", "Indiana", "Colorado", "Colorado", "Colorado", "Virginia", "Virginia", "Virginia"),
pvals_open = c(0.0, 0.120, 1, NA, 0.192, 0.121, NA, 1, 0.30),
pvals_closed = c(NA, NA, NA, 0.029, NA, NA, 0.00, NA, NA)
)
df2 <- df %>%
mutate(
val = coalesce(pvals_open, pvals_closed),
sig = if_else(val > 0.05, "> 0.05", "<= 0.05")
) %>% select(outcome, sample, val, sig)
ggplot(df2) +
aes(x = outcome, y = val, group = sample, colour = sample, shape = sig) +
geom_point(size = 2, position = position_dodge(0.8)) +
geom_hline(yintercept = 0.05, linetype = "dotted") +
coord_flip(ylim = c(0,1)) +
theme(
# legend.justification=c(0, 1),
# legend.position = "none",
# legend.title = element_blank(),
# legend.background = element_rect(fill = NA),
text = element_text(size=11),
panel.background = element_rect(fill = NA),
panel.border = element_rect(fill = NA, color = 'grey75'),
axis.ticks = element_blank(),
plot.title = element_text(size=14),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank()) +
scale_y_reverse(breaks=c(0.00,0.05,0.5,1), expand=c(0,0), labels=c("0","0.05", "0.5","1"))
To other words, I am wary of pulling out the borders on either side, because I think this could suggest to readers that the bounds are not 0 or 1. If either a) geom_points could spill over borders, or b) borders could be pulled out but then the borders on the left and right are made white, and I could manually put lines at 0 and 1, that would be desirable.
Thanks!