FrankRalphBob FrankRalphBob - 2 months ago 11
R Question

Change legend from gradient to specific data values

So, I am very new to R, so excuse my question's idiotic nature. So, currently my data is plotting as such:

operators

which is fine and dandy, except that the operator values are 1071361 & 1116576. The client wants the legend to specify only the specific operator values and not the gradient between the values. The operator values can be different from dataset to dataset in value and number, so I cannot hard code them. Currently, I have the points as such:

g = ggplot(DAT, aes(x=Date, y=Value))
g = g + geom_point(aes(colour=Operator)) + guides(col = guide_legend(override.aes = list(fill = unique(DAT$Operator))))


But this is not getting me to my desired result. Any ideas about how to do this?

Thanks in advance for your help.

Answer

Does the following achieve your goal?

DAT$Operator <- as.factor(as.character(DAT$Operator))

g = ggplot(DAT, aes(x=Date, y=Value))
g = g + geom_point(aes(colour=Operator))