r - Change name of point labels in -


i know how add point labels when using ggplot2 using geom_text()

p <- ggplot(mtcars, aes(x=wt, y=mpg, label=rownames(mtcars))) p + geom_text() 

enter image description here

but if want change "fiat x1-9" "worst car ever" without changing entries in original dataframe? there way rename point in plot within geom_text()?

thanks much.

you can override aesthetic or use in initial expression:

nms <- rownames(mtcars) p + geom_text(aes(label = replace(nms, nms == "fiat x1-9", "worst car ever"))) 

edit

if not want create new object can use this. point of advice, don't become attached one-liners. fun, creating object best readability, debugging, , accuracy.

p + geom_text(aes(label = replace(rownames(mtcars), rownames(mtcars) == "fiat x1-9", "worst car ever"))) 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -