I have this image that is the result of this ggplot command:
causative_snp = filter(LOD_table, str_detect(`Causative SNP Chromosome: Calculation Method`, "Chr. 23")) %>%
pull(`Causative SNP`) %>%
extract(1)
ggplot(data = LOD_table, mapping = aes(x = `Locus (Mb)`, y = `LOD Score`)) +
facet_grid(`Test Type` ~ `Causative SNP Chromosome: Calculation Method`) +
geom_vline(xintercept = causative_snp, color = "blue", size = .5, alpha = .5, linetype = "dashed") +
geom_point(alpha = .01, size = .1, na.rm = TRUE) +
labs(title = "LOD Score Tests",
subtitle = paste("Causative SNP (on Chromosome 23): ", causative_snp, " Mb", sep = ""),
caption = "The causative SNP line is plotted on non-causative SNP chromosomes to show the lack of correlation.")
So basically, what I want to happen is for the 2 leftmost columns (the ones that start with Chr. 19
) to not have a vertical line, while the 2 rightmost columns (the ones that start with Chr. 23
) do have a vertical line.
The Causative SNP Chromosome: Calculation Method
of my LOD_table dataset is of type factor
. There are four values: Chr. 19: Haplotype-Based
, Chr. 19: SNP-Based
, Chr. 23: Haplotype-Based
, and Chr. 23: SNP-Based
, and these values become the column names in my plot as a result of facet_grid()
. What I was wondering if I could do would be to have some sort if
statement that checks that if the column value starts with "Chr. 23", it will plot the vertical line, but if else, it will plot no vertical line. I guess my problem is, then, that I am unsure how to do this while in a facet_grid()
.
I am currently dealing with my problem with the caption, but ideally, I would like for the caption to not have to be there. Any help appreciated, thanks.