0

My dataset looks like this:

imgur picture.

I'm trying to create a simple scatter plot with data labels that are names (first and last name).

I used geom_text_repel in ggrepel to create data labels, but the labels on the plot are just numbers in the order of the data points in my dataset.

For example, if you look at the first datapoint, instead of the label being "Stephen Curry" it is "1"

I have no idea why this is happening and I can't find anyone else who even has my problem, let alone a solution.

Code:

ggplot(gravity,
       aes(TS., USG., label = rownames(gravity))) +
  geom_point(aes(TS., USG.), color='black') + 
  geom_text_repel(aes(TS., USG., label = rownames(gravity)))

imgur image

The image above shows the plot created by the code. As you can see, the labels are just the ordering number instead of the name. I don't see why this happening considering those ordering numbers are not part of the dataset I imported.

Thanks in advance

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
  • 2
    Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Mar 25 '19 at 02:03
  • It doesn't look like your data *has* rownames (which is what you told `ggplot` to use as labels). What do you get if you enter `rownames(gravity)` in your console? – Z.Lin Mar 27 '19 at 15:33
  • You set `label = rownames(gravity)` which, from your posted data are just numbers. You probably want `label = Name` – divibisan Mar 27 '19 at 15:33

0 Answers0