I want to create a .PDF of 2 simple matrices (see below) and 3 simple plots.
The problem I’m experiencing is that if i try to make 3 ggplots within 1 PDF i only get the last plot in the PDF.
I made some examples of both matrices:
testM1<-structure(c(3.97324499399863e-10, 3.4941052533535e-09, 0.000223879747651954,
0.000317346286270709, 4.95475331444513e-05, 9.37455248795082e-06,
0.00479174197985962, 0.0117719601999346, 1.95538874649056e-05,
0.0112286943879835, 0.00938438613835775, 4.94275399906971e-05,
0.0707123514324416, 0.272635105975824, 0.0017364758608557, 2429999.00716101,
647545.748442555, 376514.280488326, 357881.804554609, 312416.957044385,
311751.97469005, 307725.707067659, 290422.886020279, 263015.211836681,
257847.262909701, 249313.738258419, 236842.707415477, 229077.242836832,
225838.837415727, 222252.913031706), .Dim = c(15L, 2L), .Dimnames = list(
NULL, c("tRapAffinities", "score")))
testM2<-structure(c(0.541113046067412, 0.0702310495185636, 6.51934974465011,
7.32828989739312, 6.15333571096081, 5.41881440001279, 3.90607027852561,
6.73133704899702, 6.39382638746547, 5.08064000102212, 4.82103531583203,
5.4283713899347, 6.24047041218676, 8.8615052151427, 5.67248639940994,
2429999.00716101, 647545.748442555, 376514.280488326, 357881.804554609,
312416.957044385, 311751.97469005, 307725.707067659, 290422.886020279,
263015.211836681, 257847.262909701, 249313.738258419, 236842.707415477,
229077.242836832, 225838.837415727, 222252.913031706), .Dim = c(15L,
2L), .Dimnames = list(NULL, c("mashAffinities", "score")))
To use the GGPLOT()
function i need to convert the matrices in a data.frame (see function)
plotAll<-function(rankedtRapdf = testM1, rankedMashdf = testM2) {
rankedtRapdf <- as.data.frame(rankedtRapdf)
rankedMashdf <- as.data.frame(rankedMashdf)
l<- ggplot()
l + geom_point(aes(x=rankedtRapdf$tRapAffinities,y=rankedtRapdf$score)) + scale_x_log10() + scale_y_log10()
t <- ggplot()
t + geom_point(aes(x=rankedMashdf$mashAffinities,y=rankedMashdf$score), colour = "red")
k <- ggplot()
k + geom_point(aes(x=rankedMashdf$mashAffinities,y=log10(rankedtRapdf$tRapAffinities), colour = "darkred"))+
ggtitle('Measured Mash affinities VS. measured tRap affinities') +
theme_bw() + labs(x="MASH affinities", y="log10() tRap affinities") +
theme(axis.title=element_text(face="bold.italic", size="12", color="brown"), legend.position="top")
}
When i try to run this function within a call to pdf()
i only get the last plot back.
How can i make those 3 plots at once so that it can be applied on multiple datasets?
p.s. another problem i`m experiencing is that if i convert the matrix to a data.frame within the function i got the following error: Error in eval(expr, envir, enclos) : object 'rankedMashdf' not found