i am trying to implement a function to plot two time series plots using a single function but it returns only one here is code what is wrong with it
visualize <- function(x) {
x<-data.frame(x)
x1 <- x[x$chr == 1, ]
x2 <- x[x$chr != 1, ]
t1<-data.frame("range"=1:nrow(x1))
t2<-data.frame("range"=1:nrow(x2))
t1$testsample_first<-exp(x1$testSample1)
t1$testsample_second<-exp(x1$testSample2)
t2$testsample_first<-exp(x2$testSample1)
t2$testsample_second<-exp(x2$testSample2)
dygraph(t1);dygraph(t2)
}
(visualize(scon))
It is plotting second one only .I tried to implement by calling a second function in first but same result.
So, if you want to return multiple things, you can always put results into a list and return that instead. So you'll have something like return(list(plotA = plotA, plotB = plotB)) or similar. You can then use output from this list as you would any other output.
To draw multiple curves in one plot, different functions are created separately and the curve() function is called repeatedly for each curve function. The call for every other curve() function except for the first one should have added an attribute set to TRUE so that multiple curves can be added to the same plot.
Combine multiple ggplot on one page.Use the function ggarrange() [ggpubr package], a wrapper around the function plot_grid() [cowplot package]. Compared to plot_grid(), ggarange() can arrange multiple ggplots over multiple pages.
You need to return the two objects together in a list
:
list(plot(t1), plot(t2))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With