vstack graph not shown in juno (Gadfly) - julia

I've just started with Julia and Juno but have extensive knowledge in other data analysis frameworks.
While working with Julia in Juno trying to plot some graphs and combinations of graphs with Gadfly, I've stumbled over the following:
fig1 = plot(df, x=:time, y=:pressure, Geom.line)
fig2 = plot(df, x=:time, y=:temperature, Geom.line)
create graphs in the plot pane as expected.
On the other hand, the result of
fig3 = vstack(fig1, fig2)
does not show up in the plot pane.
I've tried calling fig3 and show(fig3) but those just return the Compose.Context object on the shell.
Am I missing something?

Related

is there any facility to plot a line?

I have some nodes and I want to plot them. some of them connect to others. I don't know How can I plot a line in Julia ? would you please help me?
for example a line as follow:
y=2x+5
thank you
As an addition to the answer above, actually in Plots.jl it is even simpler. Just pass a function to plot like this:
plot(x->2x+5)
you typically will want to pass axis ranges which you can do like this:
plot(x->2x+5, xlim=(0,5), ylim=(5,15))
you can also plot several functions at once:
plot([sin, cos, x->x^2-1], label=["sin", "cos", "x²-1"], xlim=(-2,2), ylim=(-1,3))
The result of the last plotting command is:
Try looking at Julia's documentation about plotting as well as this tutorial found by searching Julia plots on a web search engine.
Plotting y = 2x+5 in Julia v1.1 :
using Pkg
Pkg.add("Plots") # Comment if you already added package Plots
using Plots
plotly() # Choose the Plotly.jl backend for web interactivity
x = -5:5 # Change for different xaxis range, you can for instance use : x = -5:10:5
y = [2*i + 5 for i in x]
plot(x, y, title="My Plot")

How to plot multiple curves on same plot in julia?

I am using julia to build linear regression model from scratch. After having done all my mathematical calculations, I need to plot a linear regression graph
I have a scatter plot and linear fit (Linear line) plots separately ready, How do I combine them or use my linear fit plot on scatter plot?
Basically, how do I draw multiple plots on a single plot in Julia?
Note: Neither do I know python or R
x = [1,2,3,4,5]
y = [2,3,4,5,6]
plot1 = scatter(x,y)
plot2 = plot(x,y) #line plot
#plot3 = plot1+plot2 (how?)
Julia doesn't come with one built-in plotting package, so you need to choose one. Popular plotting packages are Plots, Gadfly, PyPlot, GR, PlotlyJS and others. You need to install them first, and with Plots you'll also need to install a "backend" package (e.g. one of the last three mentioned above).
With Plots, e.g., you'd do
using Plots; gr() # if GR is the plotting "backend" you've chosen
scatter(point_xs, point_ys) # the points
plot!(line_xs, line_ys) # the line
The key here is the plot! command (as opposed to plot), which modifies an existing plot rather than creating a new one.
More simply you can do
scatter(x,y, smooth = true) # fits the trendline automatically
See also http://docs.juliaplots.org/latest/
(disclaimer: I'm associated with Plots - others may give you different advice)

Layered ScatterD3 plots?

Is it possible to overlay multiple layers of ScatterD3 plots on top of one another? I haven't been able to find this anywhere in either the vignettes or searching StackExchange/Google.
I'm curious, since folks have been able to make PCA Vector Loading plots using ScatterD3. If one could overlay this on top of another plot with the points (akin to what's possible with ggplot2 or ggvis layers), you could have a gorgeous and interactive PCA plot. Additionally, you might be able to outline points (since point stroke currently isn't an option).
Does anyone have any insight or workarounds?
It is possible, but more difficult. I would recommend using plotly package. You'll be able to use the View tab in the RStudio and more easily examine your 3D scatter by rotating. The color scheme is also easier to add This post attempts to tackle a similar, though not identical. A good (free) tutorial for plotly can be found here through DataCamp.
Question answered here thanks to the author of ScatterD3. To generate a full PCA plot, you need to redefine the dataframe being plotted like so:
library(FactoMineR)
library (ScatterD3)
out<-PCA(iris[,1:4],scale.unit = TRUE, graph=FALSE)
cc1<-data.frame(out$ind$coord)
cc2<-data.frame(out$var$coord)
points <- data.frame(x = cc1$Dim.1,
y = cc1$Dim.2,
color = iris$Species,
lab = row.names(iris),
type = rep("point", 150))
arrows <- data.frame(x = cc2$Dim.1,
y = cc2$Dim.2,
color = "Blue",
lab = row.names(cc2),
type = rep("arrow", 4))
data1 <- rbind(points, arrows)
scatterD3(data1, x = x, y = y,
lab = lab, type_var = data1$type, col_var = color)

Errors in ggplot and plotly

When I try graphing my double bar graph using ggplot on r- shiny using plotly's interface, the double bar graph is getting data from random places and does not properly graph the plot.
I have used this interface on single bar plots and it has worked perfectly and correctly displays the data and graph but with double bar plots, it just uses random data? The regular ggplot plot is fine but when I transform it to a plotly it screws up.
output$tvpn <- renderPlotly({
mpolfinal4$Partner.Name= factor(mpolfinal4$Partner.Name,
levels=names(sort(table(mpolfinal4$Partner.Name),
decreasing=TRUE)))
tv = ggplot(mpolfinal4, aes(x =Partner.Name, fill=Domain.Name)) +
geom_bar(colour="black") +
theme(axis.text.x=element_text(angle=90,hjust=1)) +
ggtitle("Total Views by Partner Name, and Domain Name")
out = ggplotly(tv)
out
})
Has anyone experienced this issue/know how to fix it?

R- spplot not plotting raster stack in gWidgets GUI

I have been building a small GUI for climate analysis using gWidgets in R. Progress has been slow but steady until I hit a problem trying to display my raster stack of results using spplot().
The issue is that only the first raster in the stack is plotted and the rest are not. This issue occurs regardless if:
I produce the plot using a handler within the GUI.
If the plot is produced using a handler within a addHandlerChanged/addHandlerClicked function.
If the plot is loaded to the GUI directly from the R console.
As above but using using levelplot().
If plot() is used, results are displayed correctly but only the first 16 are displayed (I have 24 graphs) and the scales are not merged producing difficulty in interpreting the results.
Here is some example code to illustrate the issue:
require(gWidgets)
require(raster)
## create example GUI plot area
win = gwindow("Graph test")
nb = gnotebook(container=win,expand=T)
plots = ggraphicsnotebook(container=nb)
## create raster stack
rs=list()
for(i in 1:24){
rs1=raster()
rs1[]=rnorm(3600)
rs[i]=rs1
}
rs=stack(rs)
## attempt to plot stack
spplot(rs) ##plot is not produced correctly with only the first raster plotted
##compare this to plotting in a normal window
windows()
spplot(rs)
Here is an example of the expected plot (left) and the actual (right) using the above code.
If anybody has any ideas how to get around this or any alternative plotting options for raster stacks I would love to hear them.
(please note that similar results are produced if I open a separate window using windows() within the GUI or if I use levelplot())
Cheers
To those who may be interested. After 3.5 years and a many trials, including recordPlot(), the gridGraphics package and imager::capture.plot(), the only solution that I found was to save the graph as an image and then plot it in the window using rasterImage()
require(gWidgets)
require(gWidgetsRGtk2)
require(RGtk2)
require(raster)
require(png)
options(guiToolkit="RGtk2")
## create raster stack
rs=list()
for(i in 1:24){
rs1=raster(nrow=2,ncol=2)
rs1[]=rnorm(4)
rs[i]=rs1
}
rs=stack(rs)
##save plot as png
png("out.png")
spplot(rs)
dev.off()
img = readPNG("out.png")
## create example GUI plot area
win = gwindow("Graph test")
nb = gnotebook(container=win,expand=T)
plots = ggraphicsnotebook(container=nb)
##plot
par(mar=rep(0,4))
plot(1, type="n", axes=F, xlab="", ylab="")
usr = par("usr")
rasterImage(img, usr[1], usr[3], usr[2], usr[4])

Resources