Julia not able to convert Array to a series data for plotting

I got the code to work but I did not get a plot. Instead, I got this:

Sending you the entire cell:

begin
	
	countries = ["Italy", "Germany", "India", "United Kingdom"]
	y = DataFrame() # empty dataframe
	
	dates = names(df)[begin:end-4]
	date_format = Dates.DateFormat("m/d/y")
	x_axis = parse.(Date, dates, date_format) .+ Year(2000)

	for country in countries    
    	data_dfr = get_country(df,country); 
    	data_dfr = DataFrame(data_dfr);           
    	df_rows, df_cols = size(data_dfr);
    	data_dfl = stack(data_dfr, 5:df_cols);       
    	y[!,Symbol("$country")] = data_dfl[!,:value]
	end

	rows,cols = size(y)
	
	i = 1 
	n = rows
	
	while i <= n
    	if prod(isa.(collect((y)[i,:]),Number))==0
       		delete!(y,i)
       		global x_axis = x_axis[1:end .!= i]
       		global n -= 1
    	end
    	global i += 1
	end
	
	gr(size=(900,600))
	
	@df y plot(x_axis, cols(1:cols), 
	    label =  reshape(names(y),(1,length(names(y)))),
	    xlabel = "Time",
	    ylabel = "Total number of reported cases",
	    xticks = x_axis[1:7:end],
	    xrotation = 45,
	    marker = (:diamond,4),
	    line = (:line, "gray"),
	    legend = :topleft,
	    grid = false,
	    framestyle = :semi,
	    legendfontsize = 9,
	    tickfontsize = 9,
	    formatter = :plain
	    )
	
	y.One_million = Array{Union{Missing,Float64},1}(missing,size(y,1));
	y.One_million .= 10^6.0;
	
	display(@df y plot!(x_axis, y[!,cols+1],
	       linestyle = :dot,
	       linewidth = 5,
	       color = :red,
	       label = names(y)[cols+1]))
	
	y = select!(y, Not([:One_million])); 
end

You should break this into two (or more) steps so that you can more clearly figure out where the issues are. In one cell, read in the data. In the next cell, create the DataFrame you want to plot. In the next cell, plot it. You asked for plotting help, but based on the responses your issue was not with plotting but with manipulating the data. That would have been clear up front had you done things in multiple steps.

4 Likes

Actually, I found the problem. This chunk of code hides/overrides the plot.

	y.One_million = Array{Union{Missing,Float64},1}(missing,size(y,1));
	y.One_million .= 10^6.0;
	
	display(@df y plot!(x_axis, y[!,cols+1],
	       linestyle = :dot,
	       linewidth = 5,
	       color = :red,
	       label = names(y)[cols+1]))
	
	y = select!(y, Not([:One_million])); 

When I commented it out, the plot became visible.