Combine subplots in Julia - julia

In Julia I know one way of combining subplots as the this:
p1=plot(...)
p2=plot(...)
p3=plot(...)
plot(p1, p2, p3, layout(3,1))
However, suppose that I don't know beforehand the number of subplots, like when I generate the subplots based of some parameters passed to a function, then how would I accomplish the same thing?
What I tried was that I made an array to contain all the subplots
Plot_array=[p1, p2, p3]
(again, the number of elements of Plot_array can be changed based on what passed to a function)
and then
plot(Plot_array, layout=(...))
However, this did not work. Does anyone know any better way?

Something like this should work
plot(Plot_array..., layout=(length(Plot_array), 1))
Three dots is so called "splat" operator: https://docs.julialang.org/en/v1/manual/functions/#Varargs-Functions

Related

How can I give certain colour on certain groups in R plot function?

I'm trying to give my tsne plot few different colour label.
What I scripted is
plot(XXX.tsne,
col=c("red", "blue")[
grepl("A|B|C|D|E", colnames(dta.log))+1],
cex=0.5, pch=19)
XXX.tsne has been given above already.
It gives two colours to my plot, but now I need to combine more than two colours in a same plot, i.e. A|B|C|D|E= blue, F|G|H|I=yellow and k|l|m|n =red.
I think grepl function would not be useful here. What can I do?
Instead of grepl which is only giving you two values use the match function;. You didn't offer a test case but perhaps something like:
<other args>,
col=c("red", "blue")[
match( colnames(dta.log),c("A","B","C","D","E") )],..
The match function is 1-based and designed for exactly this purpose rather than needing to have +1 bump. You may need to watch out for items in the dta.log object that do not match those options. See the ?match page for your exception handling if needed.

How can i plot an array of numbers in WxMaxima?

I need to plot all the elements of a[n] 0<=n<=30. Is that possible in maxima?
These are the numbers i need to plot
by the way, you can help others help you by typing your work so far into your question. That way people can see it immediately instead of having to go look for it.
About plotting the points, remember that a[n] as you have defined it is a so-called array function instead of a list or array. The plotting functions can work with lists, I believe. So you need to evaluate your function at a number of points and then plot the points.
Something like: mypoints: makelist([n, a[n]], n, 1, 30); to generate the points. Then with the points in hand, there are different ways to plot them. You can try: plot2d([discrete, mypoints]); There are other ways; see wxdraw2d for example.

how to combine facet_grid and ggstatsplot::grouped_ggbetweenstats?

Is there any way we can combine ggstatsplot::grouped_ggbetweenstats and facet_grid to get multiple plots in one scale, something like below?
data<-data.frame(technology=(a,a,a,a, b,b,b,b,c,c,c,c,d,d,d,d), rate=c(2,5,7,9,2,5,7,9,2,5,7,9,2,5,7,9),return=c(20,15,20,30,50,13,10,8,7,9,11,23,17,20,13,16))
In short, no, it is not possible to combine ggplot2::facet_grid() with ggstatsplot::grouped_ggbetweenstats() (or any grouped_ functions actually) because the latter doesn't output a ggplot object.
ggstatsplot uses a wrapper around cowplot::plot_grid() function (called combine_plots()) in the backdrop to arrange the individual plots and any adjustment you want to make to how individual plots are arranged in the combined plot can be made in the grouped_ function itself using ... argument.
For example, see the documentation for grouped_ggbetweenstats() function here-
https://indrajeetpatil.github.io/ggstatsplot/reference/grouped_ggbetweenstats.html#arguments

Cufflinks: how to subplot heatmaps w/ Cufflinks in Jupyter/ipython Notebook?

I have read the Cufflinks examples. The only subplots examples are generated from a single DataFrame with a subplots=True parameter and an optional shape parameter (i.e. df.iplot(..., subplots=True, shape=(...), ...). As I understand it, the mechanism is that when subplots=True is provided, each column of the DataFrame is plotted as a subplot.
Now, about heatmaps in Cufflinks. The example in the same link shows that the DataFrame of a heatmap of N * M is simply an N * M DataFrame where the column names and indexes tells the x and y coordiates and the values are the "heat" of each cell of the grid.
Combining the two, it seems that if I have two heatmaps (thus two DataFrames), I cannot plot both in a subplot-fashion, because subplots require a single DataFrame and I cannot combine two heatmap DataFrames into one.
Anyone has any idea how it might work?
BTW, I also tried plotly.offline.iplot(..., subplots=True, ...) and the parameter is not supported.
EDIT
There is another question (from me, too) asking about doing the same in plotly, which got answered. So if you are working w/ plotly directly then that's the answer you might want to take a look.
This question is about using Cufflinks to achieve the same. It still seems impossible (or at least very difficult) to me.
You can use the following:
import cufflinks as cf
df1=cf.datagen.heatmap()
df2=cf.datagen.heatmap()
cf.subplots([df1.figure(kind='heatmap'),df2.figure(kind='heatmap')]).iplot()
You can do this with as many heatmaps, and you can also use the shape parameters.

equivalent to MatLab "bar" function in R?

Is there an function in R that does the same job as Matlab's "bar" function?
R does have a "barplot" function in the library graphics, however, it is not the same.
The Matlab bar(X,Y) (verbatim excerpt from MATLAB documentation) "draws a bar for each element in Y at locations specified in X, where X is a vector defining the x-axis intervals for the vertical bars." (emphasis mine)
However, the R barplot function does not allow one to specify locations.
Perhaps there is a method in ggplot2 that supports this? I am only able to find standard bar charts in ggplot2.
No, barplot is not the same as bar, but you should read the whole help. You can do many things to position the bars. The first is simply their order in Y. You could insert spaces if you wish (additional 0s). If you have X and Y then sort Y on X (Y[order(X)]) and plot it. If you need to change positions use the "space" and "width" arguments. It's not as straightforward as specifying X values I suppose but it's definitely more useful in most situations. Generally what you want to adjust is widths of bars and spaces between bars. Their position on the X-axis should be arbitrary. If the position on the X-axis is really meaningful then you should be using line plots, not bar graphs.
In R:
barplot(rbind(1:10, 2:11), beside=T, names.arg=1:10)
In MATLAB:
>> bar(1:10, [(1:10)' (2:11)'])
Read up on par . Then observe, for example:
x<-c(1,2,4,5,6)
y<-c(3,4,3,4,2)
plot(x,y,type='h',lwd=6)
Edit: yes, I know this doesn't (yet) plot multiple data sets, but I would hope you can see simple ways to make that happen, with spacings, colors, etc. specified to your exact liking :-)
Sounds vaguely like the R stepfun. On the other hand one would need to know what "draws a bar" means before saying it is not the same as barplot(..., horiz=TRUE) One would, of course, need to examine some more detailed evidence such as data and plots before arriving at a conclusion, however. #John Colby should be congratulated for adding some specificity to the discussion. The axis function is probably what Quant Guy needs education regarding.

Resources