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

Color facetting fails when combined with a contour layer #1098

Open
phipsgabler opened this issue Feb 13, 2018 · 2 comments · May be fixed by #1436
Open

Color facetting fails when combined with a contour layer #1098

phipsgabler opened this issue Feb 13, 2018 · 2 comments · May be fixed by #1436

Comments

@phipsgabler
Copy link

phipsgabler commented Feb 13, 2018

I was trying to plot two traces of points over a function contour:

df = vcat(DataFrame(x = rand(100), y = rand(100), v = :one),
          DataFrame(x = rand(100), y = rand(100), v = :two))
plot(layer(x = linspace(0, 1, 100), y = linspace(0, 1, 100), z = (x,y) -> x + y, Geom.contour),
     layer(df, x = :x, y = :y, color = :v, Geom.point))

But doing so results in an error, which seems to have to do with the color argument:

Error showing value of type Gadfly.Plot:
ERROR: MethodError: Cannot `convert` an object of type Symbol to an object of type Float64

This may have arisen from a call to the constructor Float64(...),
since type constructors fall back to convert methods.
Stacktrace:
 [1] apply_scale(::Gadfly.Scale.ContinuousColorScale, ::Array{Gadfly.Aesthetics,1}, ::Gadfly.Data, ::Vararg{Gadfly.Data,N} where N) at /home/philipp/.julia/v0.6/Gadfly/src/scale.jl:585
 [2] apply_scales(::IterTools.Distinct{Base.ValueIterator{Dict{Symbol,Gadfly.ScaleElement}},Gadfly.ScaleElement}, ::Array{Gadfly.Aesthetics,1}, ::Gadfly.Data, ::Vararg{Gadfly.Data,N} where N) at /home/philipp/.julia/v0.6/Gadfly/src/scale.jl:33
 [3] apply_scales(::IterTools.Distinct{Base.ValueIterator{Dict{Symbol,Gadfly.ScaleElement}},Gadfly.ScaleElement}, ::Gadfly.Data, ::Gadfly.Data, ::Vararg{Gadfly.Data,N} where N) at /home/philipp/.julia/v0.6/Gadfly/src/scale.jl:52
 [4] render_prepare(::Gadfly.Plot) at /home/philipp/.julia/v0.6/Gadfly/src/Gadfly.jl:670
 [5] render(::Gadfly.Plot) at /home/philipp/.julia/v0.6/Gadfly/src/Gadfly.jl:748
 [6] display(::Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}, ::MIME{Symbol("text/html")}, ::Gadfly.Plot) at /home/philipp/.julia/v0.6/Gadfly/src/Gadfly.jl:1062
 [7] display(::Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}, ::Gadfly.Plot) at /home/philipp/.julia/v0.6/Gadfly/src/Gadfly.jl:1007
 [8] display(::Gadfly.Plot) at ./multimedia.jl:194
 [9] hookless(::LastMain.LastMain.LastMain.LastMain.LastMain.Media.##7#8{Gadfly.Plot}) at 
/home/philipp/.julia/v0.6/Media/src/compat.jl:14                                         
 [10] render(::LastMain.LastMain.LastMain.LastMain.LastMain.Media.NoDisplay, ::Gadfly.Plot
) at /home/philipp/.julia/v0.6/Media/src/compat.jl:27                                    
 [11] display(::LastMain.LastMain.LastMain.LastMain.LastMain.Media.DisplayHook, ::Gadfly.Plot) at /home/philipp/.julia/v0.6/Media/src/compat.jl:9
 [12] display(::Gadfly.Plot) at ./multimedia.jl:194
 [13] hookless(::LastMain.LastMain.LastMain.LastMain.Media.##7#8{Gadfly.Plot}) at /home/philipp/.julia/v0.6/Media/src/compat.jl:14
 [14] render(::LastMain.LastMain.LastMain.LastMain.Media.NoDisplay, ::Gadfly.Plot) at /home/philipp/.julia/v0.6/Media/src/compat.jl:27
 [15] display(::LastMain.LastMain.LastMain.LastMain.Media.DisplayHook, ::Gadfly.Plot) at /home/philipp/.julia/v0.6/Media/src/compat.jl:9
 [16] display(::Gadfly.Plot) at ./multimedia.jl:194
 [17] hookless(::LastMain.LastMain.LastMain.Media.##7#8{Gadfly.Plot}) at /home/philipp/.julia/v0.6/Media/src/compat.jl:14
 [18] render(::LastMain.LastMain.LastMain.Media.NoDisplay, ::Gadfly.Plot) at /home/philipp/.julia/v0.6/Media/src/compat.jl:27
 [19] display(::LastMain.LastMain.LastMain.Media.DisplayHook, ::Gadfly.Plot) at /home/philipp/.julia/v0.6/Media/src/compat.jl:9
 [20] display(::Gadfly.Plot) at ./multimedia.jl:194
 [21] hookless(::LastMain.LastMain.Media.##7#8{Gadfly.Plot}) at /home/philipp/.julia/v0.6/Media/src/compat.jl:14
 [22] render(::LastMain.LastMain.Media.NoDisplay, ::Gadfly.Plot) at /home/philipp/.julia/v0.6/Media/src/compat.jl:27
 [23] display(::LastMain.LastMain.Media.DisplayHook, ::Gadfly.Plot) at /home/philipp/.julia/v0.6/Media/src/compat.jl:9
 [24] display(::Gadfly.Plot) at ./multimedia.jl:194
 [25] hookless(::LastMain.Media.##7#8{Gadfly.Plot}) at /home/philipp/.julia/v0.6/Media/src/compat.jl:14
 [26] render(::LastMain.Media.NoDisplay, ::Gadfly.Plot) at /home/philipp/.julia/v0.6/Media/src/compat.jl:27
 [27] display(::LastMain.Media.DisplayHook, ::Gadfly.Plot) at /home/philipp/.julia/v0.6/Media/src/compat.jl:9
 [28] display(::Gadfly.Plot) at ./multimedia.jl:194
 [29] hookless(::Media.##7#8{Gadfly.Plot}) at /home/philipp/.julia/v0.6/Media/src/compat.jl:14
 [30] render(::Media.NoDisplay, ::Gadfly.Plot) at /home/philipp/.julia/v0.6/Media/src/compat.jl:27
 [31] display(::Media.DisplayHook, ::Gadfly.Plot) at /home/philipp/.julia/v0.6/Media/src/compat.jl:9
 [32] display(::Gadfly.Plot) at ./multimedia.jl:194

The following, leaving out the contour plot or the color specification, both work without problems:

plot(layer(x = linspace(0, 1, 100), y = linspace(0, 1, 100), z = (x,y) -> x + y, Geom.contour),
     layer(df, x = :x, y = :y, Geom.point))
plot(layer(df, x = :x, y = :y, color = :v, Geom.point))

I use version 0.6.4.

@Mattriks
Copy link
Member

The issue here is that the user is wanting a continuous color scale for Geom.contour, and a discrete color scale for Geom.point. Currently Gadfly only allows one automatic color scale.
The above plot could be done like this:

theme(x) = style(default_color=parse(Colors.Colorant,x))
g = [:one, :two]
Da = [DataFrame(x=rand(20), y=rand(20), v=g[i]) for i in 1:2]
discrete_colors = ["deepskyblue", "lightgreen"]

p = plot(
      layer(x = linspace(0, 1, 100), y = linspace(0, 1, 100), z = (x,y) -> x + y, Geom.contour),
      layer(Da[1], x = :x, y = :y, theme(discrete_colors[1]), Geom.point),
      layer(Da[2], x = :x, y = :y, theme(discrete_colors[2]), Geom.point),
    Coord.cartesian(fixed=true)
)

issue1098a

But, if you want to map Geom.point to the same color scale as Geom.contour, that is possible:

 Db = vcat([DataFrame(x=rand(20), y=rand(20), v=i) for i in [0.5,1.5]]...)
p = plot(
      layer(x = linspace(0, 1, 100), y = linspace(0, 1, 100), z = (x,y) -> x + y, Geom.contour),
      layer(Db, x=:x, y=:y, color=:v, Geom.point),
      Scale.color_continuous(minvalue=0.0, maxvalue=2.0),
      Coord.cartesian(fixed=true)
)

issue1098b

@phipsgabler
Copy link
Author

Ah, I didn't realize that this is a clash of scales. I'll figure out something to work around that based on you examples. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants