Hi,
I am working on the line plot using ggplot2 library. I notice that the data point are not aligned correctly on the x-axis (different timepoints). Below is the code that I ran in R and image of the line plot. In the Image, as shown data point from T5 is aligned on T6 and T20 is not aligned as well. Please let me know how to fix the issue.
Note: Some data points are indeed missing in the middle as they are not present in the dataframe.
str(B1_Patient_Module_ID_sorted)
'data.frame': 5016 obs. of 4 variables:
$ Genes : Factor w/ 264 levels "ABHD5","ACOT4",..: 1 2 3 4 5 6 7 8 9 10 ...
$ Timepoints: num 1 1 1 1 1 1 1 1 1 1 ...
$ value : num -2.05 -8.36 -2.06 -3.84 -6.59 ...
$ X20 : Factor w/ 66 levels "M10.1","M10.2",..: 53 59 53 53 44 6 29 12 29 19 ...
..- attr(*, "names")= chr "ABHD5" "ACOT4" "ACTN4" "ACTR10" ...
pdf("B1_Module_v3.pdf", 7, 6)
for (i in seq(1, length(unique(B1_Patient_Module_ID_sorted$X20)), 1)) {
print(ggplot(B1_Patient_Module_ID_sorted[B1_Patient_Module_ID_sorted$X20 %in% levels(B1_Patient_Module_ID_sorted$X20)[i:(i)], ],
aes(x = Timepoints , y = value , group = Genes)) +
geom_point() +
geom_line(alpha = 1 , aes(col = Genes)) +
facet_wrap(~ X20) +
scale_y_continuous(name = "-Delta Ct")+
scale_x_discrete(name = "Timepoints", limits=c("1"= "T1", "2" = "T2", "3" = "T3", "5"= "T5", "6" = "T6", "7" = "T7", "8"= "T8", "9" = "T9", "10" = "T10", "11"= "T11", "12" = "T12", "13" = "T13", "14"= "T14", "15" = "T15", "16" = "T16", "17"= "T17", "18" = "T18", "19" = "T19", "20" = "T20"))+
theme_classic()+
theme(legend.position = "right") +
theme(plot.title = element_text(lineheight=.8,size =14,face = "bold"),
axis.text.x = element_text(colour="black",size=4.5,angle=0,hjust=0.5,vjust=0.5,face="plain"),
axis.text.y = element_text(colour="black",size=4,angle=0,hjust=0,vjust=0.5,face="plain"),
axis.title.x = element_text(colour="black",size=15,angle=0,hjust=.5,vjust=0,face="plain"),
axis.title.y = element_text(colour="black",size=14,angle=90,hjust=.5,vjust=.5,face="plain"),
strip.background = element_blank(),
legend.position = "right"))
}
dev.off()
Thank you,
Toufiq
Hello mohammedtoufiq91!
It appears that your post has been cross-posted to another site: https://support.bioconductor.org/p/126702/
This is typically not recommended as it runs the risk of annoying people in both communities.
@ ATpoint,
Apologies for the confusion. This would not be repeated going forward.
Can you post a snippet of the data used to generate that graph? For such an issue a reproducible example is required to properly troubleshoot.