Bileobio
Bileobio

Reputation: 150

Identifying values in R Plot

I have been trying to identify extreme values in a R ggplot2.

Is there any way to have a plot where besides the point (or instead of it) representing the values, it also shows the index? Or any other thing that allows you to quickly identify it?

The closest thing I found was with the identify() function, but it didn't work very well for me.

Any recommendations?

I'll give a basic ggplot plot:

df = data.frame(x = runif(10,0,1), y = runif(10,0,1))
ggplot(df, aes(x,y)) +
  geom_point(col="red") + theme_bw()

Upvotes: 0

Views: 478

Answers (2)

Bileobio
Bileobio

Reputation: 150

Update:

I've been trying new things. I finally got exactly what I wanted.

df = data.frame(x = runif(10,0,1), y = runif(10,0,1))
ggplot(df, aes(x,y, label = rownames(df))) +
  geom_point() + geom_text() + theme_bw()

Output

Now I can easily identify the values that I want. Hope it helps other people that are new to ggplot.

If anyone knows ways to improve it, feel free to do so.

Upvotes: 2

Jon Spring
Jon Spring

Reputation: 66870

I'd suggest installing the plotly package and then running:

plotly::ggplotly(.Last.value)

enter image description here

Upvotes: 1

Related Questions