-
Notifications
You must be signed in to change notification settings - Fork 250
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
How to place the colorkey legend inside the plot? #487
Comments
You can adjust the position of the colorkey by setting the plot(x=rand(12), y=rand(12), color=repeat(["a","b","c"], outer=[4],
Themes(key_position = :bottom)) To get colors assigned to different data points, you can either reformat your data as a Forces = vcat(
DataFrame(t = t_model, F = data_model, Source = "Model"),
DataFrame(t = t_exp, F = data_exp, Source = "Measured"))
plot(Forces, x = :t, y = :F, color = :Source, Geom.line) or explicitly specify the color grouping plot(x = [t_model, t_exp], y = [data_model, data_exp],
color = [fill("Model", length(t_model)), fill("Measured", length(t_exp))],
Geom.line) |
+1 |
Hi, |
using DataFrames, Gadfly, RDatasets
iris = dataset("datasets","iris")
d = Dict{String,String}("setosa"=>"setosa \t","versicolor"=>"versicolor \t", "virginica"=>"virginica \t")
# Add a new variable to the dataframe:
iris[:g] = map(x -> d[x], iris[:Species])
cscale = Scale.color_discrete_manual(colorant"red", colorant"green", colorant"blue")
theme1 = Theme(key_max_columns=3, key_position=:top, guide_title_position=:left)
p = plot(iris, x = :SepalWidth, y = :SepalLength, color = :g, Geom.point,
cscale, Guide.colorkey(""),
theme1
) |
Now back to the initial question in this issue (again using the using Compose
key = Guide.manual_color_key("Iris", ["setosa","versicolor","virginica"], ["red","green","blue"])
# Try changing ctxs[1] to ctxs[2] or ctxs[3] in the line below
# It seems Gadfly automatically renders 3 possible keys
mykey = render(key, Theme(), Gadfly.Aesthetics())[1].ctxs[1]
# Try changing context(7,6) to context(0.75w,0.25h) in the next line
kctx = compose(context(), (context(7,6), mykey))
p = plot(iris, x = :SepalLength, y = :PetalLength, color = :g, Geom.point,
cscale, Theme(key_position=:none),
Guide.annotation(kctx)
) |
How to place the colorkey legend inside the plot? How to control colorkey legend location?
The text was updated successfully, but these errors were encountered: