Hmm, tricky one. Maybe something like this:

t_melted = melt(t, [:_type, :rank])
t_melted[:isspeed] = t_melted[:variable] .== :speed

plot(t_melted,
     ygroup=:isspeed, x=:rank, y=:value, color=:variable,
     Geom.subplot_grid(Geom.point, free_y_axis=true),
     Scale.discrete_color_manual("purple", "orange"))



On Friday, July 25, 2014 2:56:43 PM UTC-7, Leah Hanson wrote:
>
> Yay! Thank you. That does make things a lot easier. I think I'm better 
> understanding how to use melt.
>
> However, now there's another plot I want to make. For one :_type, I want 
> to make two subplots (vertically stacked). The top one should have :thing1 
> and :thing2 in different colors; the bottom one should have :speed. (The :x 
> is always :rank.)
>
> I tried melting it, but I'm not sure how to get two variables on one plot 
> and one on the other:
> ~~~
> julia> reds = t[t[:_type] .== "red",:]
> 3x5 DataFrame
> |-------|-------|------|-------|--------|--------|
> | Row # | _type | rank | speed | thing1 | thing2 |
> | 1     | "red" | 1    | 10.0  | 0.0    | 0.0    |
> | 2     | "red" | 2    | 11.1  | 0.1    | 0.2    |
> | 3     | "red" | 3    | 12.4  | 0.3    | 0.0    |
>
> julia> m_reds = melt(reds,[:_type,:rank],[:speed,:thing1,:thing2])
> 9x4 DataFrame
> |-------|----------|-------|-------|------|
> | Row # | variable | value | _type | rank |
> | 1     | speed    | 10.0  | "red" | 1    |
> | 2     | speed    | 11.1  | "red" | 2    |
> | 3     | speed    | 12.4  | "red" | 3    |
> | 4     | thing1   | 0.0   | "red" | 1    |
> | 5     | thing1   | 0.1   | "red" | 2    |
> | 6     | thing1   | 0.3   | "red" | 3    |
> | 7     | thing2   | 0.0   | "red" | 1    |
> | 8     | thing2   | 0.2   | "red" | 2    |
> | 9     | thing2   | 0.0   | "red" | 3    |
>
> julia> plot(m_reds,
>             ygroup=:variable, x=:rank, y=:value, color=:variable,
>             Geom.subplot_grid(Geom.point))
> ~~~
>
> Another problem is that I want :thing1 and :thing2 to be on one y-scale 
> and :speed to be on a different one. (The x-axis scale is the same for 
> both.) I don't want to set them each separately to a specific scale, just 
> let them each be separately determined automatically.
>
> Thanks for your help,
> Leah
>
>
> On Fri, Jul 25, 2014 at 4:01 PM, Daniel Jones <[email protected] 
> <javascript:>> wrote:
>
>> Oh, I see. I think the easiest way would be to rearrange the data with 
>> the melt function.
>>
>>
>> melt(t, [:_type, :rank, :speed]) makes a table like:
>>
>> |-------|----------|-------|---------|------|-------|
>> | Row # | variable | value | _type   | rank | speed |
>> | 1     | thing1   | 0.0   | "red"   | 1    | 10.0  |
>> | 2     | thing1   | 0.1   | "red"   | 2    | 11.1  |
>> | 3     | thing1   | 0.3   | "red"   | 3    | 12.4  |
>> | 4     | thing1   | 0.2   | "green" | 1    | 8.0   |
>> | 5     | thing1   | 0.1   | "green" | 2    | 7.0   |
>> | 6     | thing1   | 0.2   | "green" | 3    | 9.0   |
>> | 7     | thing1   | 1.0   | "blue"  | 1    | 1.0   |
>> | 8     | thing1   | 0.2   | "blue"  | 2    | 2.0   |
>> | 9     | thing1   | 0.1   | "blue"  | 3    | 3.0   |
>> | 10    | thing2   | 0.0   | "red"   | 1    | 10.0  |
>> | 11    | thing2   | 0.2   | "red"   | 2    | 11.1  |
>> | 12    | thing2   | 0.0   | "red"   | 3    | 12.4  |
>> | 13    | thing2   | 1.0   | "green" | 1    | 8.0   |
>> | 14    | thing2   | 0.5   | "green" | 2    | 7.0   |
>> | 15    | thing2   | 0.0   | "green" | 3    | 9.0   |
>> | 16    | thing2   | 1.0   | "blue"  | 1    | 1.0   |
>> | 17    | thing2   | 0.2   | "blue"  | 2    | 2.0   |
>> | 18    | thing2   | 0.1   | "blue"  | 3    | 3.0   |
>>
>> With which the plot can be simplified to:
>>
>> plot(melt(t, [:_type, :rank, :speed]),
>>      ygroup=:_type, x=:rank, y=:value, color=:variable,
>>      Geom.subplot_grid(Geom.point),
>>      Scale.discrete_color_manual("purple", "orange"))
>>
>>
>>
>> On Friday, July 25, 2014 12:05:02 PM UTC-7, Leah Hanson wrote:
>>
>>> That's not quite it. I think the :_type values being color names is 
>>> confusing things. I don't want the dots to be colored by :_type.
>>>
>>> I would like dots for :thing1 to be in purple and the dots for :thing2 
>>> to be in orange. So every dot in the first layer needs to be purple and 
>>> every data in the second layer needs to be orange.
>>>
>>> Thanks,
>>> Leah
>>>
>>>
>>> On Fri, Jul 25, 2014 at 1:36 PM, Daniel Jones <[email protected]> 
>>> wrote:
>>>
>>>>
>>>> I think this will do the trick, if I understand what you're going for.
>>>>
>>>>  plot(t,layer(Geom.subplot_grid(Geom.point),ygroup=:_
>>>> type,x=:rank,y=:thing1,color=:_type),
>>>>         layer(Geom.subplot_grid(Geom.point),ygroup=:_type,x=:rank,
>>>> y=:thing2,color=:_type),
>>>>         Scale.discrete_color_manual("red", "green", "blue"))
>>>>
>>>>
>>>> On Friday, July 25, 2014 10:51:14 AM UTC-7, Leah Hanson wrote:
>>>>
>>>>> Thank, that's very helpful. :)
>>>>>
>>>>> This is what worked:
>>>>> ~~~
>>>>> plot(t,layer(Geom.subplot_grid(Geom.point),ygroup=:_type,x=:
>>>>> rank,y=:thing1,color=:_type),
>>>>>               layer(Geom.subplot_grid(Geom.p
>>>>> oint),ygroup=:_type,x=:rank,y=:thing2,color=:_type))
>>>>> ~~~
>>>>>
>>>>> However, now I'd like to color by layer instead of by :_type, since I 
>>>>> want the two layers of dots to be different colors.
>>>>>
>>>>> This does not work:
>>>>> ~~~
>>>>> plot(t,layer(Geom.subplot_grid(Geom.point),ygroup=:_type,x=:
>>>>> rank,y=:thing1,color="red"),
>>>>>               layer(Geom.subplot_grid(Geom.p
>>>>> oint),ygroup=:_type,x=:rank,y=:thing2,color="blue"))
>>>>> ~~~
>>>>>
>>>>> I've also tried passing the color argument into Geom.point or 
>>>>> Geom.subplot_grid. I tried setting the value of color to be a 
>>>>> "Scale.discrete_color_manual", but the color aesthetic did not consider 
>>>>> that to be an appropriate type.
>>>>>
>>>>> How do assign per-layer colors?
>>>>>
>>>>> Thanks,
>>>>> Leah
>>>>>
>>>>>
>>>>> On Fri, Jul 25, 2014 at 12:34 PM, Johan Sigfrids <[email protected]
>>>>> > wrote:
>>>>>
>>>>>> I think you might have to put the Geom.subplot_grid inside the layers.
>>>>>>
>>>>>>
>>>>>> On Friday, July 25, 2014 7:37:48 PM UTC+3, Leah Hanson wrote:
>>>>>>>
>>>>>>> I am trying to make a relatively complicated graph in Gadfly, and am 
>>>>>>> struggling.
>>>>>>>
>>>>>>> This is some sample data with the same structure as my data.
>>>>>>> ~~~
>>>>>>> julia> t = readtable("testdata.csv")
>>>>>>> 9x5 DataFrame
>>>>>>> |-------|---------|------|-------|--------|--------|
>>>>>>> | Row # | _type   | rank | speed | thing1 | thing2 |
>>>>>>> | 1     | "red"   | 1    | 10.0  | 0.0    | 0.0    |
>>>>>>> | 2     | "red"   | 2    | 11.1  | 0.1    | 0.2    |
>>>>>>> | 3     | "red"   | 3    | 12.4  | 0.3    | 0.0    |
>>>>>>> | 4     | "green" | 1    | 8.0   | 0.2    | 1.0    |
>>>>>>> | 5     | "green" | 2    | 7.0   | 0.1    | 0.5    |
>>>>>>> | 6     | "green" | 3    | 9.0   | 0.2    | 0.0    |
>>>>>>> | 7     | "blue"  | 1    | 1.0   | 1.0    | 1.0    |
>>>>>>> | 8     | "blue"  | 2    | 2.0   | 0.2    | 0.2    |
>>>>>>> | 9     | "blue"  | 3    | 3.0   | 0.1    | 0.1    |
>>>>>>> ~~~
>>>>>>>
>>>>>>> Currently, I am trying to make a plot with three rows; each row has 
>>>>>>> a plot with two layers. The rows are by :_type. The x-axis for 
>>>>>>> everything 
>>>>>>> is :rank. The two layers should be scatterplots of :thing1 and :thing2.
>>>>>>>
>>>>>>> I have tried several variations, here is one of them:
>>>>>>> ~~~
>>>>>>> julia> plot(t,Geom.subplot_grid(Geom.point),ygroup=:_type,layer(x=:
>>>>>>> rank,y=:thing1),layer(x=:rank,y=:thing2))
>>>>>>> Error showing value of type Plot:
>>>>>>> ERROR: The following aesthetics are required by Geom.point but are 
>>>>>>> not defined: x, y
>>>>>>>
>>>>>>>  in error at error.jl:21
>>>>>>>  in assert_aesthetics_defined at /usr/local/google/home/lhanson
>>>>>>> /.julia/v0.3/Gadfly/src/aesthetics.jl:148
>>>>>>>  in render at /usr/local/google/home/lhanson/.julia/v0.3/Gadfly/
>>>>>>> src/geom/point.jl:27
>>>>>>>  in render_prepared at /usr/local/google/home/lhanson
>>>>>>> /.julia/v0.3/Gadfly/src/Gadfly.jl:718
>>>>>>>  in render at /usr/local/google/home/lhanson/.julia/v0.3/Gadfly/
>>>>>>> src/geom/subplot.jl:234
>>>>>>>  in render_prepared at /usr/local/google/home/lhanson
>>>>>>> /.julia/v0.3/Gadfly/src/Gadfly.jl:718
>>>>>>>  in render at /usr/local/google/home/lhanson/.julia/v0.3/Gadfly/src/
>>>>>>> Gadfly.jl:673
>>>>>>>  in display at /usr/local/google/home/lhanson/.julia/v0.3/Gadfly/
>>>>>>> src/Gadfly.jl:922
>>>>>>>  in display at /usr/local/google/home/lhanson/.julia/v0.3/Gadfly/
>>>>>>> src/Gadfly.jl:837
>>>>>>>  in print_response at REPL.jl:140
>>>>>>>  in print_response at REPL.jl:125
>>>>>>>  in anonymous at REPL.jl:584
>>>>>>>  in run_interface at ./LineEdit.jl:1377
>>>>>>>  in run_frontend at ./REPL.jl:816
>>>>>>>  in run_repl at ./REPL.jl:170
>>>>>>>  in _start at ./client.jl:399
>>>>>>> ~~~
>>>>>>>
>>>>>>> How do I put layers inside a subplot?
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Leah
>>>>>>>
>>>>>>
>>>>>
>>>
>

Reply via email to