Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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"))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading