R programming


I have the following program in R: It plots a graph. I want to include a functionality such that whenever I hover over the points on my graph I am able to view the information associated with each of the points.

Data = read.csv(file = "data.csv", 
                header = TRUE, sep = ",")
OAS = matrix(Data[1])
OASD = matrix(Data[2])
#reg1 <- lm(as.matrix(OAS)~as.matrix(OASD))
reg1 <- lm(as.matrix(Data[1])~as.matrix(Data[2]))
plot(t(Data[2]), t(Data[1]),main="OAS vs OASD",xlab="OASD", ylab="OAS")
text(Data$class3, Data$class4, Data$Maturity.Date)

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Matthew RichardsonProduct CoordinatorCommented:
I've never seen it done where you can hover over a point and get an immediate popup with the result unless you use a in-depth graphics package that included interactive plotting, because it sounds like you don't want all the values showing.

Have you tried using the built in "identify" function included in R's graphics package? I put together what I think would work for your dataset:
identify(t(Data[2], t(Data[1], labels=row.names(Data))
coords <- locator(type="l") 

Open in new window

This will make a list with the coordinates that you could make into a data frame if that is what you wanted. Not sure what your intended purpose is with the information but you could label the graph with something different, I just chose the row names of your data set.

Alternatively, you could use this function:
identifyPch <- function(x, y = NULL, n = length(x), pch = 19, ...)
  xy <- xy.coords(x, y); x <- xy$x; y <- xy$y
  sel <- rep(FALSE, length(x)); res <- integer(0)
  while(sum(sel) < n) {
    ans <- identify(x[!sel], y[!sel], n = 1, plot = FALSE, ...)
    if(!length(ans)) break
    ans <- which(!sel)[ans]
    points(x[ans], y[ans], pch = pch)
    sel[ans] <- TRUE
    res <- c(res, ans)

identifyPch(t(Data[2], t(Data[1])

Open in new window

Which would automatically return the list of points you selected while also seeing which one's were selected if you don't want anything appearing on the graph itself.

Let me know if that is something like what you are looking for.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
camper12Author Commented:
Hi Matthew,

I am trying to incorporate a tooltip: something like given in

However, when I do the following

install_github('rCharts', 'ramnathv')

I get an error

Downloading github repo ramnathv/rCharts@master
Error in curl::curl_fetch_memory(url, handle = handle) :
  Timeout was reached

Any idea how I can resolve this?

Matthew RichardsonProduct CoordinatorCommented:
I just tried downloading it myself the way their website says and it worked for me.  It sounds like an issue with one of the dependency packages from "devtools" is incomplete.  

Try reinstalling the "devtools" package and all its dependencies:
install_github('rCharts', 'ramnathv')

Open in new window

And see if that helps.  I was able to use their first and second examples just fine doing that.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

camper12Author Commented:
Installed devtools again including dependencies. I still get the same error.
Matthew RichardsonProduct CoordinatorCommented:
Try putting this line of code before the install code:

options(download.file.method = "wininet")
camper12Author Commented:
Tried this. Still does not work.
Matthew RichardsonProduct CoordinatorCommented:
You might be behind firewall and need to use proxy settings from 'httr' package?

Fingers crossed...

set_config( config( ssl_verifypeer = 0L ) )
camper12Author Commented:
Tried it. Still get the same error. The proxy maybe the cause. I am looking into it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.