0

I want to create a scatterplot that above certain x and y values has labeled points, and points with no labels below these values.

I was thinking about something like

plot(data[,2]~data[,3], ylim=rev(range(data[,2])), xlim=c(-20,20), log="y", type="n")
text(data[,2]~data[,3], labels=ifelse(data[,2] < 0.05 && data[,3] > 1, data[,1], points(y,x)))

but it gives me this error:

Error in ans[!test & ok] <- rep(no, length.out = length(ans))[!test &  : 
replacement has length zero
In addition: Warning message:
In rep(no, length.out = length(ans)) :
'x' is NULL so the result will be NULL

I found some similar questions here on SO, but nothing that could be adapted to my needs - at least with my limited knowledge.

(I am a newbie in R, so please bear with my question.)

LinuxBlanket
  • 165
  • 1
  • 6

1 Answers1

0

There are two issues with

text(data[,2]~data[,3], labels=ifelse(data[,2] < 0.05 && data[,3] > 1, data[,1], points(y,x)))

Checkout this answer : R - boolean operators && and || To understand the difference between & and && , your case "&" would make more sense. The second issue is

points(y,x)

This part of code is called when the logical response is "FALSE" ; ie the FALSE branch of if condition ; points i am guessing is a local function that takes in param x & y ; but x and y haven't been instantiated in the parent.frame (scope of ) the ifelse . So when you fix the "&"; you will get an error surrounding point(y,x). Make sure the function that you need to execute when

data[,2] < 0.05 & data[,3] > 1

is false will return a value.

Yash
  • 307
  • 3
  • 10
  • I corrected the && mistake, but it gives me the same error as before – LinuxBlanket Oct 05 '17 at 16:09
  • text(data[,2]~data[,3], labels=ifelse(data[,2] < 0.05 & data[,3] > 1, data[,1], data[,2])); try that and see if you get the data points on the there. If that's the case ; like I pointed point(y,x) obviously needs to corrected. – Yash Oct 05 '17 at 16:19