I gave shapes and colors manually to 4 curves and points using ggplot, but when I am trying to get the legend, everything is in black. How do I color the legend shapes?
This is my code
ggplot() +
geom_line(data = combined_data, aes(x = number_of_compactions, y = anhydrate_100),
linetype = 5, size = 1, color = "red") +
geom_point(data = combined_data, aes(x = number_of_compactions, y = anhydrate_100,
shape = "CBZ Anhydrate 100 MPa"),
size = 4, color = "red") +
geom_line(data = combined_data, aes(x = number_of_compactions, y = anhydrate_250),
size = 1, color = "blue") +
geom_point(data = combined_data, aes(x = number_of_compactions, y = anhydrate_250,
shape = "CBZ Anhydrate 250 MPa"),
size = 4, color = "blue") +
geom_line(data = combined_data, aes(x = number_of_compactions, y = dihydrate_100),
linetype = 5, size = 1, color = "purple") +
geom_point(data = combined_data, aes(x = number_of_compactions, y = dihydrate_100,
shape = "CBZ Dihydrate 100 MPa"),
size = 4, color = "purple") +
geom_line(data = combined_data, aes(x = number_of_compactions, y = dihydrate_250),
size = 1, color = "black") +
geom_point(data = combined_data, aes(x = number_of_compactions, y = dihydrate_250,
shape = "CBZ Dihydrate 250 MPa"),
size = 4, color = "black") +
labs(x = "Number of Compactions", y = TeX("\\textbf{Sticking Mass (\\textbf{$\\mu}g)}")) +
scale_x_continuous(breaks = seq(0, 100, by = 10),
expand = c(0,0),
limits = c(0, 105)) +
scale_y_continuous(breaks = seq(0, 160, by = 20),
expand = c(0,0),
limits = c(0, 150)) +
scale_shape_manual(values = c(1, 16, 2, 17),
labels = c("CBZ Anhydrate 100 MPa", "CBZ Anhydrate 250 MPa",
"CBZ Dihydrate 100 MPa", "CBZ Dihydrate 250 MPa")) +
scale_fill_manual(values = c("red", "blue", "purple", "black"),
labels = c("CBZ Anhydrate 100 MPa", "CBZ Anhydrate 250 MPa",
"CBZ Dihydrate 100 MPa", "CBZ Dihydrate 250 MPa")) +
theme(panel.background = element_rect(fill = NA),
panel.border = element_rect(fill = NA, colour = "black", size = 1.2),
axis.text.y = element_text(color = "black", size = 12, face = "bold"),
axis.text.x = element_text(colour = "black", size = 12, face = "bold"),
axis.title.x = element_text(size = 18, face = "bold"),
axis.title.y = element_text(size = 18),
legend.title = element_blank(),
legend.background = element_rect(fill = NA),
legend.box.background = element_rect(fill = NA),
legend.key = element_rect(fill = NA),
legend.position = "top")
Things I tried are in the code.