-
Notifications
You must be signed in to change notification settings - Fork 251
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
Stat.x_jitter with multiple Geoms #1254
Comments
The right way to do this is: plot(x=x, y=y, ymin=ymin, ymax=ymax,
layer(Geom.point, Geom.line, Geom.errorbar, Stat.x_jitter)
) So the Gadfly rules are:
Yes these rules could be added to docs somewhere, maybe here. And a future development could be chained Stats (#570) |
i had no idea it worked this way. documenting would be great! |
I made this example which highlights several features of Gadfly. Do you think it might go into the docs somewhere? using DataFrames, Gadfly
# Make the data for the points and error bars.
n_points = 30
gshift = 2
sigmoid(x) = 1 ./ (1 .+ exp.(-x))
x = randn(n_points) * 3 # This gives a nice spread f
group = rand(n_points) .< 0.5
y = sigmoid(x)
y[group.==1] = sigmoid(x[group.==1] .+ gshift)
ymin = y - rand(n_points)./5
ymax = y + rand(n_points)./5
df = DataFrame(x=x, y=y, ymin=ymin, ymax=ymax, group=group)
# Make the data for the smooth lines.
finex = -10:0.001:10
finey1 = sigmoid(finex)
finey2 = sigmoid(finex .+ gshift)
# Since the two layers share a legend they must have the same group levels.
df2 = DataFrame(x = [finex;finex], y = [finey1; finey2], group = [finey1.*0; finey1.^0])
color_list = ["green","red"]
# These colors can be any color in Colors.color_list.
# Using Colors
# for clr in color_list
# @assert clr in keys(Colors.color_list)
# end
c = Scale.color_discrete_manual(color_list..., levels=[true, false])
t = Theme(errorbar_cap_length=0mm)
jitter = Stat.x_jitter(range=0.5)
g = Guide.colorkey(title="My Legend", labels=["Greenies", "Reddies"])
p = plot(
layer(df, x=:x, y=:y, ymin=:ymin, ymax=:ymax, color=:group, Geom.point, Geom.errorbar,jitter),
layer(df2,x=:x, y=:y, color=:group, Geom.line),
c,t,g, Guide.title("The jitter moves the points off the line")
)
# By jittering the layer, we jitter Geom.point and Geom.errorbar together. |
Here's another way, containing the 2 rules in my previous post: n_points = 30
x = randn(n_points)*3
gshift = rand([0,2], n_points)
y = sigmoid(x+gshift)
df = DataFrame(x=x, y=y, ymin=y-rand(n_points)./5, ymax=y+rand(n_points)./5, g=gshift)
plot(y=[sigmoid, x->sigmoid(x+2)], xmin=[-10], xmax=[10], Geom.line, Stat.func(100), color=[0,2],
layer(df, x=:x, y=:y, ymin=:ymin, ymax=:ymax, color=:g, Geom.point, Geom.errorbar,
Stat.x_jitter(range=0.5)),
Scale.color_discrete_manual(["red","green"]..., levels=[0,2]),
Guide.colorkey(title="Function", labels=["Sigmoid(x)", "Sigmoid(x+2)"]),
Guide.xlabel("x"),
Theme(errorbar_cap_length=0mm, key_position=:inside)
) Also red/green is not a good color combination |
@Mattriks if you're ever in San Francisco, I'll get you some 🍺. Great work as always. |
juliacon is in DC this summer, my home town. if either of you planned on going, i'd come up for a day. |
Example:
This jitters just the error bars. TO get the desired effect one must
Is that the "right" way to do this? If so, then it isn't a bug, just missing documentation, but I thought I would make this issue for others to find.
Would it be appropriate for me to make a PR adding this an example to the docs?
The text was updated successfully, but these errors were encountered: