p <- ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(colour = manufacturer))
# String legend can be set in the `guides()` function
p + guides(colour = guide_stringlegend(ncol = 2))
# The string legend can also be set as argument to the scale
p + scale_colour_viridis_d(guide = "stringlegend")
Run the code above in your browser using DataLab