I have a ggplot
with a geom_text()
:
geom_text(y = 4, aes(label = text))
The variable text has the following format:
number1-number2
I want to know if it is possible to define a color for the number1 and another color for number2 (example: red and green color)
Thanks!
One way is if you have for example the label texts of number1 and number2 as separate columns in the data frame:
You may also try
annotate
:I defined the labels and positions outside the
annotate
call, which possibly makes it easier to generate these variables more dynamically, e.g. if "number1" in fact could be calculated from the original data set, or positions be based on range of x and y.