1

I'm recently trying to make some nice interactive plots using iplots and qtlcharts, but didn't manage to find a feasible solution to add labels or legends on it. Anyone knows how to add text to an interactive plot in R?

Below are some codes for testing.

library(qtlcharts)
x <- rnorm(100)
grp <- sample(1:3, 100, replace=TRUE)
y <- x*grp + rnorm(100)
iplot(x, y, grp)

Is there some function like: plot(x, y); text(0,0, labels = "test") for adding text to interactive plot?

edit: Thanks Rafael and TheBiro for the answers. Basically, I wanted to add a permanent text (and maybe lines as well) in the interactive plot like what we achieve using text() in normal plots. Correspondent code in normal plot:

plot(x, y); text(-2,0, labels = "test");abline(h=-1)

Is it possible?

Hao
  • 11
  • 2

2 Answers2

1

What is this text that you want to add? Is it the information "X", "Y" and "Group" for each point in your plot?

Try this:

iplot(x, y, grp, 
  indID = paste("x =", round(x,1),  "<br/>",
                "y =", round(y, 1), "<br/>", 
                "group =", grp))
Rafael Cunha
  • 239
  • 2
  • 6
  • Thanks Rafael. Is it possible to add a permanent text to the interactive plot? The text that I want to add is not related to the informations of the variables, but rather a permanent label for the whole plot. – Hao May 05 '17 at 11:34
0

You can add labels like this:

iplot(x, y, grp, chartOpts=list(xlab="X Label", ylab="Y Label"))
cirofdo
  • 1,074
  • 6
  • 22
  • Is it possible to add/edit text besides the x/y labels. For example, can I add a label "This is an interactive plot!" in the topleft corner? – Hao May 05 '17 at 11:38