I've created a small set of data in an excel sheet, the example being baseball stats, and uploaded it to R. I have no issue creating a basic scatter plot using the data as well as changing the colors, shapes, and giving dots different colors based on where certain data came from (example being red dots for players from school a, blue bots for players from school b, etc.).
My issue is trying to give the dots labels of the name of the players the dots represent using geom_text()
. I've search through different websites and YouTube videos trying to see if someone had described my problem as well as show a solution. So far I'm not having much luck.
This is the code that I've seen to be having the most "results" from:
library(ggplot2)
ggplot(sportsref_download, aes(x=HR, y=SO)) +
geom_point() +
geom_text(
label=rownames,
nudge_x = 0.25, nudge_y = 0.25,
check_overlap = T
)
So far this is the error message that keeps popping up:
Error in geom_text(): ! Problem while setting up geom aesthetics. ℹ Error occurred in the 2nd layer. Caused by error in rep(): ! attempt to replicate an object of type 'closure'