Reputation: 23898
Could not figured out why manual colours are not rendering properly. Any hints!!
library(tidyverse)
tb1 <-
tibble(
X = seq(1:50)
, A = rnorm(n = 50, mean = 100, sd = 8)
, B = rnorm(n = 50, mean = 150, sd = 6)
, C = rnorm(n = 50, mean = 175, sd = 5)
, D = rnorm(n = 50, mean = 200, sd = 5)
)
tb1
Plot1 <-
ggplot(tb1, aes(x = X)) +
geom_point(aes(y = A, colour = "orange")) +
geom_line(aes(y = B, colour = "black")) +
geom_line(aes(y = C, colour = "green")) +
geom_line(aes(y = D, colour = "red")) +
scale_colour_manual(
name = ''
, values = c("orange" = "orange", "black" = "black", "green" = "green", "red" = "red")
, labels = c("Obs", "Fit1", "Fit2", "Fit3")
)
Plot1
Upvotes: 0
Views: 35
Reputation: 46908
If you don't add the labels, you see that they are ordered alphabetically:
ggplot(tb1, aes(x = X)) +
geom_point(aes(y = A, colour = "orange")) +
geom_line(aes(y = B, colour = "black")) +
geom_line(aes(y = C, colour = "green")) +
geom_line(aes(y = D, colour = "red")) +
scale_colour_manual(
name = ''
, values = c("orange" = "orange", "black" = "black", "green" = "green", "red" = "red")
So you needa arrange the order using breaks:
ggplot(tb1, aes(x = X)) +
geom_point(aes(y = A, colour = "orange")) +
geom_line(aes(y = B, colour = "black")) +
geom_line(aes(y = C, colour = "green")) +
geom_line(aes(y = D, colour = "red")) +
scale_colour_manual(
name = ''
, values = c("orange" = "orange", "black" = "black", "green" = "green", "red" = "red"),
breaks = c("orange","black","green","red"),
, labels = c("Obs", "Fit1", "Fit2", "Fit3")
)
Upvotes: 1