I am interested in plotting paired samples from my dataset. Here, I have 4 samples taken from blood and 4 samples taken from SF (which are paired). I am interested in plotting the variable “freqcd8bytissue” for this paired analysis using geom_line and geom_point in ggplot2, with each sample being plotted as a separate point. This is then facetted by a variable “clusters_names”.
After loading the dataset, I create statistics (step 2 in code below) comparing the difference in variable “freqcd8bytissue” in paired SF vs Blood (variable “Tissue”) samples:
#step 1: load dataset
#step 2: create stats
stat.test_freqcd8bytissue <- cd8clusterbytissue %>%
group_by(clusters_names) %>%
pairwise_t_test(freqcd8bytissue ~ Tissue, p.adjust.method = "bonferroni") %>%
add_significance()
stat.test_freqcd8bytissue <- stat.test_freqcd8bytissue %>% add_xy_position(x = "Tissue")
The new dataframe being created looks like this and it appears that for most of the cluster_names variable, the n per group (Blood or SF) is 4 (some exceptions exist):
Now onto plotting:
#plot
ggplot(cd8clusterbytissue, aes(x = Tissue, y = freqcd8bytissue)) +
geom_line(aes(group = sample_id)) +
geom_point(aes(color = Tissue)) + facet_wrap(~ clusters_names) + theme_classic() +
scale_color_manual(values = c("#f2a21e", "#88a0c4")) + theme(legend.position = "none") + xlab(NULL) +
ylab("Frequency of CD8 subcluster in all CD8 cells, per patient") + stat_pvalue_manual(stat.test_freqcd8bytissue, label = "p.adj")
This gives me the following graph and this is where I am facing an issue: it appears that only two paired samples have been plotted for most of the levels of the clusters_names variable (because I only see two dots per Tissue):
Can anyone please suggest how I can amend the code so that I am able to see 4 dots per Tissue for the levels of clusters_names that have n=4 each?