I produced a table that I then plotted. The plot is all wonky though, the values have mixed themselves up to make a perfect line. See below.
graph = plot(a, x = :Years_mean, y = :Overall_mean, Geom.line)
How do I get it back to normal? Or what did I do to screw it up?
Thanks
Can you provide a minimal example of what a
is? Gadfly distinguishes between continuous and discrete variables, and so there may be multiple options to do what you want, depending on whether the original data is continuous, discrete, or a TimeType.
Here is a sample. Both columns are type any
. Row two is blank. All values were rounded to digits = 2
. I had a little trouble putting the df here, had to delete some info, so I hope I didn’t lose anything valuable.
│ Overall_mean │ Years_mean │
│ 80.37 │ 9.3 │
│ │ │
│ 95.23 │ 9.03 │
│ 90.7 │ 4.57 │
│ 89.57 │ 9.75 │
│ 88.36 │ 16.43 │
│ 88.02 │ 3.75 │
│ 85.47 │ 10.22 │
│ 85.31 │ 7.9 │
│ 83.7 │ 5.1 │
│ 82.92 │ 7.1 │
│ 80.55 │ 11.79 │
│ 80.43 │ 9.0 │
│ 79.53 │ 4.53 │
│ 79.17 │ 6.62 │
│ 78.71 │ 10.4 │
│ 78.22 │ 9.22 │
What are the blank values e.g. " " or “”?
They are " ". What’s that other one you typed?
Your data is messy because your mixing different types which don’t promote well. Even something like this won’t work:
replace(a, " "=>NaN)
My solution is:
a0 = [ 80.37 9.3; " " " "; 95.23 9.03; 90.7 4.57; 89.57 9.75;
88.36 16.43; 88.02 3.75; 85.47 10.22 ; 85.31 7.9;
83.7 5.1; 82.92 7.1; 80.55 11.79 ; 80.43 9.0 ;
79.53 4.53; 79.17 6.62; 78.71 10.4; 78.22 9.22]
a = DataFrame(a0, [:Years_mean, :Overall_mean])
[x[isa.(x, String)] .= NaN for x in eachcol(a)]
# or
ifelse.(isa.(a, String), NaN, a)
a
The DataFrames docs might provide further help.
Thank you. I’ll give that a try. So basically if those blanks weren’t there it ought to work because then everything would be the same type?
Yes, it should work if columns are of the same type. In Gadfly, you can try to make variables discrete or continuous by adding e.g. Scale.x_discrete
or Scale.x_continuous
, but that will only work if the values can be promoted to a discrete or continuous type.
In my work, I opted to drop missing values
df = dropmissing(df, :Overall_mean)
for DataFrames.