r - Create 3 GGplots in 1 PDF within 1 function -


this question has answer here:

i want create .pdf of 2 simple matrices (see below) , 3 simple plots.

the problem i’m experiencing if try make 3 ggplots within 1 pdf last plot in pdf.

i made 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 ggplot() function need convert matrices in 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 try run function within call pdf() last plot back.

how can make 3 plots @ once can applied on multiple datasets?

p.s. problem i`m experiencing if convert matrix data.frame within function got following error: error in eval(expr, envir, enclos) : object 'rankedmashdf' not found

is there reason need use function plot these?

you can more this. option looking onefile = true.

rankedtrapdf <- as.data.frame(testm1) rankedmashdf <- as.data.frame(testm2) l <- ggplot( rankedtrapdf  )+   geom_point( aes( x = trapaffinities , y = score ) ) +    scale_x_log10() +    scale_y_log10()  t <- ggplot( rankedmashdf )+   geom_point(aes( mashaffinities , y = score ), colour = "red")  k <- ggplot( rankedmashdf ) +   geom_point( aes( 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")    # print plots pdf pdf( "~/myplots.pdf" , onefile = true ) print(l) print(t) print(k) dev.off() 

enter image description here


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -