Reputation: 605
In Gadfly, I am trying to color horizontal lines based on data. But since color of Geom.hline
is not an aesthetic, but only an argument, my approach fails. How can I pass color form the data to the color argument?
My attempt:
using DataFrames, Gadfly
test = DataFrame(y = [1,2], group = ["a", "b"])
p = plot(test, yintercept = :y, color=:group, Geom.hline)
Desired behavior:
Two horizontal lines with two different colors (colored by group
).
Actual behavior:
Two horizontal lines with the same color, warning message The following aesthetics are mapped, but not used by any geometry: color
.
Upvotes: 0
Views: 36
Reputation: 61
You can pass a color
argument to Geom.hline
rather than to the plot
function. As an example:
using DataFrames, Gadfly
test = DataFrame(y=[1, 2], group=["a", "b"])
p = plot(test, yintercept=:y, Geom.hline(color=["red", "blue"]))
This gives me the following result:
In your case you would have to map your groups against colors
Upvotes: 0