Вы можете указать цвет / тип линий / шкалы формы вручную.
library("tidyverse")
df <- tibble::tribble(
~n, ~times, ~algorithms, ~shapes, ~linetypes, ~colours,
1L, 0.000271833, "algo1", "x", "solid", "blue",
11L, 0.000612195, "algo1", "x", "solid", "blue",
1L, 0.000267802, "algo2", "x", "solid", "red",
11L, 0.000644297, "algo2", "x", "solid", "red",
1L, 0.000280468, "algo3", "x", "solid", "green",
11L, 0.000816817, "algo3", "x", "solid", "green",
1L, 0.000452015, "algo4", "x", "solid", "black",
11L, 0.00271677, "algo4", "x", "solid", "black",
1L, 0.000271255, "algo5", "o", "dashed", "blue",
11L, 0.000622194, "algo5", "o", "dashed", "blue",
1L, 0.000271107, "algo6", "o", "dashed", "red",
11L, 0.000701686, "algo6", "o", "dashed", "red",
1L, 0.000267631, "algo7", "o", "dashed", "green",
11L, 0.000723341, "algo7", "o", "dashed", "green",
1L, 0.000451016, "algo8", "o", "dashed", "black",
11L, 0.00124079, "algo8", "o", "dashed", "black"
)
df %>%
ggplot(aes(
x = n, y = times,
linetype = algorithms,
shape = algorithms,
colour = algorithms
)) +
geom_line() +
# Comment out `geom_point` to check that the line type is
# as specified but is overplotted by the shape in the legend
geom_point(size = 4) +
xlab("n") +
ylab(paste0("Execution time (ms)")) +
ggtitle("asdf") +
scale_color_manual(
values = deframe(df %>% select(algorithms, colours))
) +
scale_linetype_manual(
values = deframe(df %>% select(algorithms, linetypes))
) +
scale_shape_manual(
values = deframe(df %>% select(algorithms, shapes))
) +
theme(legend.position = "bottom")
Создано в 2019-10-30 пакетом Представить (v0.3.0)