ggplot – how to set the color of lines using qplot without mapping colors to a variable?

let’s say that I have a very simple piece of code like this:

qplot(1:5, 1:5, geom = "line", color = "blue")

Unfortunately, this code will not produce a blue line, but, instead, it will try to create mapping for the color and thus you will see that the legend has appeared on the right side of the graph with the value "blue" being shown in red.

When using normal ggplot you can do something like this:

ggplot(data, aes(x = x, y = y))+
  geom_line(color = "blue")

So I thought that it would also work in qplot like that. But it doesn’t. How can I create a simple blue line without mapping the color to a variable?

>Solution :

Another way would be to use the inhibit function I() like this:

qplot(1:5, 1:5, geom = "line", colour = I("blue"))

Leave a Reply