<commit_before>using Gadfly, DataFrames
function Gadfly.plot(path::RegularizationPath, gadfly_args...; x=:segment, varnames=nothing, selectedvars=:nonzeroatAICc, showminAICc=true)
    β=coef(path)
    if hasintercept(path)
        β = β[2:end,:]
    end

    (p,nλ)=size(β)

    if varnames==nothing
        varnames=[symbol("var$i") for i=1:p]
    end

    indata=DataFrame()
    if x==:λ
        indata[x]=path.λ
    elseif x==:logλ
        indata[x]=log(path.λ)
    else
        x=:segment
        indata[x]=1:nλ
    end
    outdata = deepcopy(indata)

    minAICcix=minAICc(path)
    if selectedvars==:nonzeroatAICc || selectedvars==:all
        for j=1:p
            if selectedvars==:all || β[j,minAICcix]!=0
                indata[varnames[j]]=vec(full(β[j,:]))
            else
                outdata[varnames[j]]=vec(full(β[j,:]))
            end
        end
    elseif typeof(selectedvars)==Vector{Int}
        for j in selectedvars
            indata[varnames[j]]=vec(full(β[j,:]))
        end
        for j in setdiff(1:p,selectedvars)
            outdata[varnames[j]]=vec(full(β[j,:]))
        end
    end

    inmdframe=melt(indata,x)
    outmdframe=melt(outdata,x)
    rename!(inmdframe,:value,:coefficients)
    rename!(outmdframe,:value,:coefficients)
    inmdframe = inmdframe[convert(BitArray,map(b->!isnan(b),inmdframe[:coefficients])),:]
    outmdframe = outmdframe[convert(BitArray,map(b->!isnan(b),outmdframe[:coefficients])),:]

    xintercept = []
    if showminAICc
        push!(xintercept,indata[minAICcix,x])
    end

    layers=Vector{Layer}()
    if size(inmdframe,1) > 0
      append!(layers, layer(inmdframe,x=x,y="coefficients",color="variable",Geom.line,xintercept=xintercept,Geom.vline(color=colorant"black")))
    end
    if size(outmdframe,1) > 0
      append!(layers,layer(outmdframe,x=x,y="coefficients",group="variable",Geom.line,Theme(default_color=colorant"lightgray")))
    end

    Gadfly.plot(layers..., Stat.xticks(coverage_weight=1.0), gadfly_args...)<commit_msg>julia v0.3 compatability<commit_after>using Gadfly, DataFrames
function Gadfly.plot(path::RegularizationPath, gadfly_args...; x=:segment, varnames=nothing, selectedvars=:nonzeroatAICc, showminAICc=true)
    β=coef(path)
    if hasintercept(path)
        β = β[2:end,:]
    end

    (p,nλ)=size(β)

    if varnames==nothing
        varnames=[symbol("var$i") for i=1:p]
    end

    indata=DataFrame()
    if x==:λ
        indata[x]=path.λ
    elseif x==:logλ
        indata[x]=log(path.λ)
    else
        x=:segment
        indata[x]=1:nλ
    end
    outdata = deepcopy(indata)

    minAICcix=minAICc(path)
    if selectedvars==:nonzeroatAICc || selectedvars==:all
        for j=1:p
            if selectedvars==:all || β[j,minAICcix]!=0
                indata[varnames[j]]=vec(full(β[j,:]))
            else
                outdata[varnames[j]]=vec(full(β[j,:]))
            end
        end
    elseif typeof(selectedvars)==Vector{Int}
        for j in selectedvars
            indata[varnames[j]]=vec(full(β[j,:]))
        end
        for j in setdiff(1:p,selectedvars)
            outdata[varnames[j]]=vec(full(β[j,:]))
        end
    end

    inmdframe=melt(indata,x)
    outmdframe=melt(outdata,x)
    rename!(inmdframe,:value,:coefficients)
    rename!(outmdframe,:value,:coefficients)
    inmdframe = inmdframe[convert(BitArray,map(b->!isnan(b),inmdframe[:coefficients])),:]
    outmdframe = outmdframe[convert(BitArray,map(b->!isnan(b),outmdframe[:coefficients])),:]

    xintercept = Float64[]
    if showminAICc
        push!(xintercept,indata[minAICcix,x])
    end

    layers=Vector{Layer}()
    if size(inmdframe,1) > 0
      append!(layers, layer(inmdframe,x=x,y="coefficients",color="variable",Geom.line,xintercept=xintercept,Geom.vline(color=colorant"black")))
    end
    if size(outmdframe,1) > 0
      append!(layers,layer(outmdframe,x=x,y="coefficients",group="variable",Geom.line,Theme(default_color=colorant"lightgray")))
    end

    Gadfly.plot(layers..., Stat.xticks(coverage_weight=1.0), gadfly_args...)
{'fraction_non_alphanumeric': 0.1561108362196932, 'fraction_numerical': 0.006927263730826323, 'mean_word_length': 3.3566810344827585, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6665345', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1502, 'n_words': 188}