0

I have created a complex plot g with ggplot with a number of series with different colors. Now, I'd like to add a few points with a manual color, without bothering about the colors of all the pre-existing series.

For example, if I do this

g + geom_point(data = dd, aes_string(x = xseries, y = yseries, color = "red" ) )

it doesn't work, obviously, because it's expecting a factor variable because it wants to associate colors to values of a variable in the data frame dd. Another trial was to assign a variable to those points (say redpoint, so the data frame ddwould contain columns "xseries", "yseries" and "redpoint") like this:

g + geom_point(data = dd, aes_string(x = xseries, y = yseries, color = "redpoint" ) )

Now, people advice to use scale_color_manual to manually define colors. However, if I do that I should explicitly state all the colors of the data series that are in g, which is quite problematic as they are several tens and it took me a while to assign them the colors I want. So, is there a method to add points with a manual color without specifying all the colors of the pre-existing plot?

Nonancourt
  • 559
  • 2
  • 10
  • 21

1 Answers1

1

Well, it looks I have found a solution to my own question, actually. The problem is solved by stating the color outside the aes_string, like

g + geom_point(data = dd, aes_string(x = xseries, y = yseries), color = "red" )

This seems to work fine.

Nonancourt
  • 559
  • 2
  • 10
  • 21