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()
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
Post a Comment