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

making scatter plots with different shaped markers (issues) #1366

Closed
SimonEnsemble opened this issue Dec 18, 2019 · 6 comments · Fixed by #1411
Closed

making scatter plots with different shaped markers (issues) #1366

SimonEnsemble opened this issue Dec 18, 2019 · 6 comments · Fixed by #1411
Assignees

Comments

@SimonEnsemble
Copy link

issue 1

plot(x=rand(4), y=rand(4), Geom.point, shape=[Shape.hexagon],
     Guide.xlabel("Re"),
     Guide.ylabel("Im")
)

automatically includes a legend, which I don't want. this seems an odd default, and how can I remove the legend?

image

issue 2

this code results in no output

plot(layer(x=rand(4), y=rand(4), Geom.point, shape=[Shape.hexagon]),
     layer(x=rand(4), y=rand(4), Geom.point, shape=[Shape.cross]),
     Guide.xlabel("Re"),
     Guide.ylabel("Im")
)

how can I make two layers with different symbols outside (without building a DataFrame)?

issue 3

the markers in the key seem to be a different size than inside the plot. is it possible to make them the same size using Theme.point_size?

image

issue 4

even in the DataFrame paradigm,

df = DataFrame(x=rand(3), y=rand(3), z=["a", "a", "b"])

plot(df, x=:x, y=:y, shape=:z, hipster_theme, shapes=[Shape.cross, Shape.circle])

how can I control which shapes are used, e.g. specify crosses and circles?

image

issue 5

is there a manual key (legend) I could make while specifying the shapes of the data? That way I could get rid of the title on the legend above, which is "z".

@Mattriks
Copy link
Member

  1. and 4. use Theme() e.g.
    Theme(key_position=:none, point_shapes=[Shape.cross, Shape.circle])
    To see all the options do dump(Theme(), maxdepth=1)

  2. Has been fixed recently on master branch (update cat_aes_var! #1333). To use master branch do

]add Gadfly#master

I'll get back to you about 3 and 5.

@Mattriks
Copy link
Member

For 5, try Guide.shapekey. Scale.shape_discrete(levels= ) can be used to set the order of the levels, which will 'match' the order in Theme(point_shapes= ). There's a generic discrete scale example in the Tutorial.

@SimonEnsemble
Copy link
Author

thanks. I am passing around a theme:

hipster_theme = Theme(default_color="orange", line_width=1mm, 
    major_label_font_size=14pt, minor_label_font_size=12pt, 
    panel_fill="ivory", minor_label_font="Courier", 
    major_label_font="Courier", point_size=5pt);

but when I for example Gadfly.push_theme(hipster_theme) then:

Gadfly.push_theme(Theme(point_shapes=[Shape.cross, Shape.star2]))
plot(layer(x=rand(4), y=rand(4), Geom.point, shape=[Shape.cross]),
     layer(x=rand(4), y=rand(4), Geom.point, shape=[Shape.star2]),
     Guide.xlabel("Re"),
     Guide.ylabel("Im"),
     Guide.shapekey(title="", labels=["zeros", "poles"])
)

to do as you say, it deletes all of the other settings in hipster_theme! :(
and I want keys in some of my plots so I wouldn't want to pass key_position=:none to my hipster_theme.

I can't seem to figure out how Scale.shape_discrete works/what its purpose is from the docs.

@Mattriks
Copy link
Member

style() is documented here e.g.

Gadfly.push_theme(hipster_theme)

plot(layer(x=rand(4), y=rand(4), Geom.point, shape=[Shape.cross]),
     layer(x=rand(4), y=rand(4), Geom.point, shape=[Shape.star2]),
     Guide.xlabel("Re"), Guide.ylabel("Im"),
     Guide.shapekey(title="", labels=["zeros", "poles"]),
    style(key_position=:none)
)

Yes Scale.shape_discrete could be better documented. The Scale.{aesthetic}_discrete() all work in the same way, which is what the tutorial example is attempting to show. The discrete scale table really needs a fourth column, showing the Theme fields that contain the "palettes" for the discrete aesthetics. E.g. Theme(point_shapes= ) is the shape palette for the shape aesthetic, Theme(alphas= ) is the alpha palette for the alpha aesthetic etc

@Mattriks
Copy link
Member

Here's an example of Scale.shape_discrete:

plot(layer(x=rand(4), y=rand(4), Geom.point, shape=["poles"]),
     layer(x=rand(4), y=rand(4), Geom.point, shape=["zeros"]),
    Scale.shape_discrete(levels=["zeros","poles"]),
     Guide.xlabel("Re"), Guide.ylabel("Im"),
     Guide.shapekey(title=""), style(point_shapes=[Shape.cross, Shape.star2])
)

@Mattriks
Copy link
Member

Mattriks commented Apr 6, 2020

issue 6

When in layers, shape aesthetic levels don't auto-group in the same way as color aesthetic levels:

pa = plot( Theme(point_size=6pt),
    layer(x=rand(4), y=rand(4), color=["A level"]),
     layer(x=rand(4), y=rand(4), color=["B level"]) )
pb = plot( Theme(point_size=6pt),
    layer(x=rand(4), y=rand(4), shape=["A level"]),
     layer(x=rand(4), y=rand(4), shape=["B level"]) )
hstack(pa, pb)

iss1366_6

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