Following is the sample code for the random chart:
library(ggplot2) ggplot(mtcars,aes(x=mpg,y=wt,color=factor(vs)))+geom_line()+theme(legend.position="top",legend.direction = "horizontal",legend.title=element_blank(),legend.key = element_blank()) and following is the output from above code:
My requirement: Instead of having two lines denoted by 0 and 1 as legend elements, I only want legend texts "0" and "1" colored as "red" and "skyblue" (same as color of lines) and remove the lines. Is this possible?
https://stackoverflow.com/questions/66701803/change-the-color-of-legend-elements-in-ggplot-r March 19, 2021 at 10:39AM
没有评论:
发表评论