Julia showing candlestick plots with just one colour - julia

I am unable to plot candlestick in Julia properly.
Here is a sample code:
using Plots
using Dates
using MarketData
using TimeSeries
gr()
ta = yahoo(:GOOG, YahooOpt(period1 = now() - Month(1)))
display(plot(ta, seriestype= :candlestick))
The output I get is below
Candlestick Plot with one colour
How to ensure that I get red & green candles?

I would update your installation. I get two colors with Julia 1.8.0-beta3 and Plots version 1.29:
https://i.stack.imgur.com/q1p7J.png

Related

Mosaic plot for a single variable in R like a puzzle not just vertical bars

How can I obtain something similar to a mosaic plot but representing just the information from a frequency table for a single variable?
mosaicplot(table(my_var)) works fine, but only shows vertical bars.
Is it possible to obtain a mosaic plot like a puzzle of different tiles instead of just vertical bars? Something similar to this image:
I had the same question, today. I found out that the graph is called treemap and at least two libraries support creating it: treemap and plotly.
As #Man.A noted, you can create a treemap with the treemap R package. A simple example:
# library
library(treemap)
#> Warning: package 'treemap' was built under R version 4.1.3
# Create data
group <- c("group-1","group-2","group-3")
value <- c(13,5,22)
data <- data.frame(group,value)
# treemap
treemap(data,
index="group",
vSize="value",
type="index"
)

Julia - Displaying several plots in the same plot (not subplot)

Plotting several series in a same plot display is possible and also several subplots in a display. But I want several plots which can be completely different things (not necessarily a series or graph of a map) to be displayed exactly in one frame. How can I do that? In Maple you assign names for each plot like
P1:=...:, P2:= ...: and then using plots:-display(P1,P2,...); and it works. But I want to do this in Julia. Let's say I have the following plots as an example;
using Plots
pyplot()
x=[1,2,2,1,1]
y=[1,1,2,2,1]
plot(x,y)
p1=plot(x,y,fill=(0, :orange))
x2=[2,3,3,2,2]
y2=[2,2,3,3,2]
p2=plot(x2,y2,fill=(0, :yellow))
Now how to have both P1 and P2 in one plot? I don't one a shortcut or trick to write the output of this specific example with one plot line, note that my question is general, for example p2 can be a curve or something else, or I may have a forflow which generates a plot in each step and then I want to put all those shapes in one plot display at the end of the for loop.
Code for a simple example of trying to use plot!() for adding to a plot with arbitrary order.
using Plots
pyplot()
x=[1,2,2,1,1]
y=[1,1,2,2,1]
p1=plot(x,y,fill=(0, :orange))
x2=[2,3,3,2,2]
y2=[2,2,3,3,2]
p2=plot!(x2,y2,fill=(0, :orange))
p3=plot(x,y)
display(p2)
p5=plot!([1,2,2,1,1],[2,2,3,3,2],fill=(0, :green))
By running the above code I see the following plots respectively.
But what I expected to see is a plot with the green rectangle added inside the plot with the two orange rectangles.
The way to plot several series within the same set of axes is with the plot! function. Note the exclamation mark! It's part of the function name. While plot creates a new plot each time it is invoked, plot! will add the series to the current plot. Example:
plot(x, y)
plot!(x, z)
And if you are creating several plots at once, you can name them and refer to them in plot!:
p1 = plot(x, y)
plot!(p1, x, z)
Well, if you do that, what you will have is subplots, technically. That's what it means.
The syntax is
plot(p1, p2)
Sorry, I don't know how to plot a whole plot (conversely to a series) over an other plot.. For what it concerns the order of the plots, you can create as many plots as you want without display them and then display them wherever you want, e.g.:
using Plots
pyplot()
# Here we create independent plots, without displaying them:
x=[1,2,2,1,1]
y=[1,1,2,2,1]
p1=plot(x,y,fill=(0, :orange));
x2=[2,3,3,2,2]
y2=[2,2,3,3,2]
p2=plot(x2,y2,fill=(0, :orange));
p3=plot(x,y);
p5=plot([1,2,2,1,1],[2,2,3,3,2],fill=(0, :green));
# Here we display the plots (in the order we want):
println("P2:")
display(p2)
println("P3:")
display(p3)
println("P5:")
display(p5)
println("P1:")
display(p1)

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)

Multiple panel plots with pheatmap

I am trying to do multipanel plots one panel being a heatmap using layout to place plots. I've been drawing heatmaps with pheatmap which provides a very convenient color scheme among other things.
The code for pheatmap is available here.
When I try using pheatmap in this way it always plots on a new page. I imagine this is because of its use of the grid package? Is there a way I can do this with pheatmap?
Example code to produce a heatmap next to a barplot but which doesn't since the heatmap gets plotted on a new page below:
xlay=layout( matrix(c(2,2,1),nrow=1) )
layout.show(xlay)
barplot(rnorm(8),horiz=T)
pheatmap(matrix(rnorm(80),nrow=8))
Make your bar plot in ggplot
bar <- ggplot()
Assign both the barplots and heatmap to a variable
heat <- pheatmap(matrix(rnorm(80),nrow=8))
then use gridExtra package to make panel plot the heatmap is saved as an object and you can plot it again by assessing the 4th item in the object
grid.arrange(bar, heat[[4]], nrow = 1)

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?

Resources