Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

line plot can not show more than 7 colors and if less than 7, all lines are connected. #130

Open
JunDamin opened this issue Oct 13, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@JunDamin
Copy link

When I plot more than 7 category as a color, it shows error as below. Also it shows wrong graph because all line connected which should be drawed by the region below 7 categories.

import TidierPlots, Random, DataFrames

region_names = ["A", "B", "C", "D", "E", "F", "G", "H"]
n_regions = length(region_names)
n_years = length(2010:2020)

years = repeat(2010:2020, n_regions)
regions = repeat(region_names, inner=n_years)
values = rand(n_regions*n_years)
df = DataFrame(year=years, region=regions, value=values)

(
    ggplot(df, @aes(x = year, y = value, color = region)) 
    + geom_line()
)
ERROR: BoundsError: attempt to access 7-element Array{RGB{Float64},1} with eltype ColorTypes.RGB{Float64} at index [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1  …  8, 8, 8, 8, 8, 8, 8, 8, 8, 8]]
Stacktrace:
  [1] throw_boundserror(A::Vector{ColorTypes.RGB{Float64}}, I::Tuple{Vector{Int64}})
    @ Base .\abstractarray.jl:737
  [2] checkbounds
    @ .\abstractarray.jl:702 [inlined]
  [3] _getindex
    @ .\multidimensional.jl:888 [inlined]
  [4] getindex
    @ .\abstractarray.jl:1291 [inlined]
  [5] (::TidierPlots.var"#81#82"{Vector{ColorTypes.RGB{Float64}}})(x::Vector{Int64})
    @ TidierPlots C:\Users\freed\.julia\packages\TidierPlots\CA1NI\src\transforms.jl:190
  [6] call_composed
    @ .\operators.jl:1044 [inlined]
  [7] (::ComposedFunction{TidierPlots.var"#81#82"{Vector{ColorTypes.RGB{Float64}}}, TidierPlots.var"#74#76"})(x::CategoricalVector{String, UInt32, String, CategoricalValue{String, UInt32}, Union{}})
    @ Base .\operators.jl:1041
  [8] (::TidierPlots.var"#31#36")(::Pair{Symbol, TidierPlots.PlottableData})
    @ TidierPlots .\none:0
  [9] iterate
    @ .\generator.jl:47 [inlined]
 [10] grow_to!(dest::Vector{Any}, itr::Base.Generator{Base.Iterators.Filter{TidierPlots.var"#32#37"{Vector{String}}, Dict{Symbol, TidierPlots.PlottableData}}, TidierPlots.var"#31#36"})
    @ Base .\array.jl:907
 [11] collect(itr::Base.Generator{Base.Iterators.Filter{TidierPlots.var"#32#37"{Vector{String}}, Dict{Symbol, TidierPlots.PlottableData}}, TidierPlots.var"#31#36"})
    @ Base .\array.jl:831
 [12] (::Makie.var"#1011#1017"{Makie.var"#1011#1012#1018"{Symbol}})(plot::TidierPlots.GGPlot)
    @ TidierPlots C:\Users\freed\.julia\packages\TidierPlots\CA1NI\src\draw.jl:110
 [13] draw_ggplot(plot::TidierPlots.GGPlot)
    @ TidierPlots C:\Users\freed\.julia\packages\TidierPlots\CA1NI\src\draw.jl:149
 [14] (::TidierPlots.var"#83#84"{TidierPlots.GGPlot})()
    @ TidierPlots C:\Users\freed\.julia\packages\TidierPlots\CA1NI\src\show.jl:76
 [15] (::Makie.var"#279#280"{@Kwargs{}, TidierPlots.var"#83#84"{TidierPlots.GGPlot}, Attributes})()
    @ Makie C:\Users\freed\.julia\packages\Makie\iRM0c\src\theming.jl:227
 [16] lock(f::Makie.var"#279#280"{@Kwargs{}, TidierPlots.var"#83#84"{TidierPlots.GGPlot}, Attributes}, l::ReentrantLock)
    @ Base .\lock.jl:229
 [17] #with_theme#278
    @ C:\Users\freed\.julia\packages\Makie\iRM0c\src\theming.jl:223 [inlined]
 [18] with_theme
    @ C:\Users\freed\.julia\packages\Makie\iRM0c\src\theming.jl:222 [inlined]
 [19] show(io::IOContext{Base.TTY}, plot::TidierPlots.GGPlot)
    @ TidierPlots C:\Users\freed\.julia\packages\TidierPlots\CA1NI\src\show.jl:75
 [20] show(io::IOContext{Base.TTY}, ::MIME{Symbol("text/plain")}, x::TidierPlots.GGPlot)
    @ Base.Multimedia .\multimedia.jl:47
 [21] (::REPL.var"#55#56"{REPL.REPLDisplay{REPL.LineEditREPL}, MIME{Symbol("text/plain")}, Base.RefValue{Any}})(io::Any)
    @ REPL C:\Users\freed\.julia\juliaup\julia-1.10.2+0.x64.w64.mingw32\share\julia\stdlib\v1.10\REPL\src\REPL.jl:273
 [22] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL C:\Users\freed\.julia\juliaup\julia-1.10.2+0.x64.w64.mingw32\share\julia\stdlib\v1.10\REPL\src\REPL.jl:569
 [23] display(d::REPL.REPLDisplay, mime::MIME{Symbol("text/plain")}, x::Any)
    @ REPL C:\Users\freed\.julia\juliaup\julia-1.10.2+0.x64.w64.mingw32\share\julia\stdlib\v1.10\REPL\src\REPL.jl:259
 [24] display(d::REPL.REPLDisplay, x::Any)
    @ REPL C:\Users\freed\.julia\juliaup\julia-1.10.2+0.x64.w64.mingw32\share\julia\stdlib\v1.10\REPL\src\REPL.jl:278
 [25] display(x::Any)
    @ Base.Multimedia .\multimedia.jl:340
 [26] #invokelatest#2
    @ .\essentials.jl:892 [inlined]
 [27] invokelatest
    @ .\essentials.jl:889 [inlined]
 [28] (::VSCodeServer.var"#69#74"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\freed\.positron\extensions\julialang.language-julia-1.124.2-universal\scripts\packages\VSCodeServer\src\eval.jl:237
 [29] withpath(f::VSCodeServer.var"#69#74"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, path::String) 
    @ VSCodeServer c:\Users\freed\.positron\extensions\julialang.language-julia-1.124.2-universal\scripts\packages\VSCodeServer\src\repl.jl:276
 [30] (::VSCodeServer.var"#68#73"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\freed\.positron\extensions\julialang.language-julia-1.124.2-universal\scripts\packages\VSCodeServer\src\eval.jl:179
 [31] hideprompt(f::VSCodeServer.var"#68#73"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})
    @ VSCodeServer c:\Users\freed\.positron\extensions\julialang.language-julia-1.124.2-universal\scripts\packages\VSCodeServer\src\repl.jl:38
 [32] (::VSCodeServer.var"#67#72"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\freed\.positron\extensions\julialang.language-julia-1.124.2-universal\scripts\packages\VSCodeServer\src\eval.jl:150
 [33] with_logstate(f::Function, logstate::Any)
    @ Base.CoreLogging .\logging.jl:515
 [34] with_logger
    @ .\logging.jl:627 [inlined]
 [35] (::VSCodeServer.var"#66#71"{VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\freed\.positron\extensions\julialang.language-julia-1.124.2-universal\scripts\packages\VSCodeServer\src\eval.jl:263
 [36] #invokelatest#2
    @ .\essentials.jl:892 [inlined]
 [37] invokelatest(::Any)
    @ Base .\essentials.jl:889
 [38] (::VSCodeServer.var"#64#65")()
    @ VSCodeServer c:\Users\freed\.positron\extensions\julialang.language-julia-1.124.2-universal\scripts\packages\VSCodeServer\src\eval.jl:34

geom_line
data: inherits from plot
x: inherits from plot
y: inherits from plot

I think it should extends the number of colors or circulate colors automatically by default.
Also I think It should draw lines by its color not connected.

test

@JunDamin JunDamin added the bug Something isn't working label Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant