I have a dataframe to plot where y_axis variable is a character one. I want to take only the last part of character with '_' as separation.
Here an example with iris dataset. As you can see, all y_axis labels are the same. How can I do it? thanks
iris$trial = paste('hello', 'good_bye', iris$Sepal.Length, sep = '_')
myfun = function(x) {
tail(unlist(strsplit(x, '_')), n = 1)
}
ggplot(iris, aes(x = Species, y = trial, color = Species)) +
geom_point() +
scale_y_discrete(labels = function(x) myfun(x)) +
theme_bw()


Sepal.Lengthbecause my problem variable, has characters + numeric. And I only want the numeric one. I cannot edit this variable on dataframe, because color variable needs all character+numeric, because color value is a named vector with character+numeric and I shouldn't edit those names, because it would contain duplicates