How to add Another Line Plot to DataFrame and CSV Plot?

Hi all,

I am trying to add another plot of Book Value per Share.
It is following this tutorial:
https://www.juliabloggers.com/using-julia-for-data-science-part-03-plotting/

this is my code:

using CSV, Dates, DataFrames, Plots, Plots.PlotMeasures, RollingFunctions

fileadhi = "./csv/IDX-Stocks/ADHI Historical Data.csv"

dfadhi = CSV.read(fileadhi, DataFrame)

dfadhi.Price .= parse.(Float64, replace.(dfadhi.Price, "," => ""))
dfadhi[!,"Change %"] .= parse.(Float64, replace.(dfadhi[!,"Change %"], "%" => ""))

dfadhi.Dates = Date.(dfadhi.Date, "mm/dd/yyyy")
tick_years = Date.(unique(Dates.year.(dfadhi.Dates)))
DateTick = Dates.format.(tick_years, "yy")
xlimsadhi = extrema([tick_years; dfadhi.Dates])

plot(dfadhi.Dates, dfadhi.Price, title="",
    xticks=(tick_years,DateTick), xlims=xlimsadhi,
    label="Adhi Karya (Price)", xlabel="", ylabel="")

# Set Book Value per Share
x = [04/01/2004 04/01/2008];
y = [300 400];
plot!(x,y, label="Book Value per Share")

But, the plot does not show:
Capture d’écran_2023-02-20_17-27-49

These are 1x2 matrices rather than column vectors, you want to either create vectors ([300, 400], note the comma) or transpose the matrices (plot(x', y'))

Your other problem is that x is not what you think it is:

julia> x
1×2 Matrix{Float64}:
 0.00199601  0.00199203

When you do 4/1/2004 you are are just dividing 4 by 1 and then the result (i.e. 4) by 2004, which gives 0.01996. Dates are created either from strings or by directly passing year, month, and day to the constructor:

julia> using Dates

julia> Date("04/01/2004", "d/m/y")
2004-01-04

julia> Date(2004, 1, 4)
2004-01-04
1 Like

I see it is wrong format then, thanks a lot! now it is working!

Sorry for asking too many questions in Discourse, it is curiosity that kills the cat.