Hello. I need your help for ggplots.
I am trying to add multiple ggplots in the same "sheet". The issue that Iam facing is that at the end of plots (both Error_gg and correct_gg) I have this error (Error: Aesthetics must be either length 1 or the same as the data (512): colour)
I wrote the following:
library(matrixStats)
library(ggplot2)
library(ggpubr)
library(grid)
dedomena_Error <-read.table("/home/kgee/Desktop/file1")
dedomena_correct <- read.table("/home/kgee/Desktop/strand_bias/file2")
correct_g <- ggplot(data=dedomena,aes(x=dedomena_correct$V3,y=dedomena_correct$V2))
Error_g <- ggplot(data=dedomena_Error,aes(x=dedomena_Error$V5,y=dedomena_Error$V4))
Error_gg <-g + geom_point(aes(colour =dedomena_Error$V5))+ geom_line(aes(dedomena_Error$V4))+ggtitle("Strand bias plot")+xlab("genome length")+ylab("genes in strand oriantation") + theme_classic()
correct_gg <-g + geom_point(aes(colour =dedomena_correct$V2))+ geom_line(aes(dedomena_correct$V3))+ggtitle("Strand bias plot")+xlab("genome length")+ylab("genes in strand oriantation") + theme_classic()
Error_gg
correct_gg
#(Error_gg +correct_gg) I dont know if its the proper way to add two plots together multiple_gg
You need to pay more attention to details, you are making a lot of syntax errors and using undefined variable names, for example:
You haven't defined dedomena, you just have defined dedomena_Error and dedomena_correct. Also, you are using invalid syntax to define the aesthetics, no need for this part dedomena_correct$.
You haven't defined g so there is nothing to add to.
See this example correcting your syntax errors (BTW notice how the example is self-contained you should do the same next time)
First of all, thanks a lot for the reply. I used the example you suggested me and works!!! I need some other specifications, if you don't mind. Reading your second correction, if I have more than more than 1 ggplots on my code how should I difined them.? "name<- ggplot(data = dedomena_correct, aes(x = V3, y = V2)) etc ? Also how to combine multiple ggplots if they have the name ggplot??
You can totally save them as individual variables, like you suggest. But I really like storing them together as a named list, b/c I think it keeps my environment cleaner.
thanks a lot for the suggestions. I used the egg as the cowplot requires the newest version of R. and I got almost what I want. So I need to practice with my new toy . I know that I have a lot to do for improving my coding appearance and I'm on this way. Once again thank you very much for your help!!!