0

I have a dataframe consists of three variables asn(this is an id),ip_used,domain_used,correct(this is binary 0 or 1). data example :

asn, ip_used,domain_used,correct

1,234,34,1
30,45,765,1
498,4,765,0
3874,876,8765,1

I have plotted ip_used and domain_used against each other for each asn in a bubble plot and now I want to specify bubbles of the entries that are equal to 1 for "correct" with a different bubble color.

Here is my current plot and my current code:

symbols(log_domused,log_ipused, circles = radius,inches=0.40, fg="black", bg="white",xlab = "# used domain",ylab="# used ips",main="dnsdb distribution of domains per ips for each ASN")

Does anybody have any idea how to do that?

UserYmY
  • 8,034
  • 17
  • 57
  • 71

1 Answers1

2

Your data:

myData <- rbind(c(1,234,34,1), c(30,45,765,1), c(498,4,765,0), c(3874,876,8765,1))
colnames(myData) <- c("asn", "ip_used", "domain_used", "correct")

myData
      asn ip_used domain_used correct
[1,]    1     234          34       1
[2,]   30      45         765       1
[3,]  498       4         765       0
[4,] 3874     876        8765       1

You can specify the color of each circle with "fg" (or "bg"):

symbols(myData[,1], myData[,3], circles=c(1,1,1,1), inches=0.40, fg=myData[,4]+1, bg="white",
        xlab = "# used domain",ylab="# used ips",
        main="dnsdb distribution of domains per ips for each ASN"
        )

fg

Karolis Koncevičius
  • 9,417
  • 9
  • 56
  • 89
  • thanks for your answer. My problem is not coloring, but because I want to put a condition, I want to say for enrties that are equal to 1 for variable "correct" use a different color. – UserYmY Nov 23 '14 at 17:44
  • Hm I am not sure I understand you then. You want to use different colors for two types of bubbles? If that is so you can specify the colors for each bubble in `fg` or `bg`. In my opinion `bg=var+1` where `var` is your conditions vector (0 or 1) should work. – Karolis Koncevičius Nov 23 '14 at 17:51
  • I want to specify my circles based on a condition that exists in the third variables. SO I have a set of bubbles that have the same colors, but I want to say if for each entry, v3=1, then the color of the bubble be blue for instance. in this case v3 is called "correct". – UserYmY Nov 23 '14 at 17:58
  • I updated my answer with the data you provided in the question. Does it address your issue now? – Karolis Koncevičius Nov 23 '14 at 18:13
  • I get this error In Ops.factor((df$correct), 1) : + not meaningful for factors – UserYmY Nov 23 '14 at 19:18
  • I see, your df$correct is a factor. You can try `as.numeric(as.character(df$correct)) + 1` instead. It will convert your factor to character and then to numeric (can't convert straight to numeric usually). – Karolis Koncevičius Nov 23 '14 at 19:22
  • Yeah it works thank you. Is there anyway for me to specify the foreground color now? Or is it automatically? – UserYmY Nov 23 '14 at 19:52
  • 1
    You should be able to specify both. use `bg=df$correct+1, fg=df$correct+1` if you want them to be of the same color. (convert to numeric first of course..). Works for me. Also you might want to do following: `colors <- as.numeric(as.character(df$correct))` And then `colors[colors==0] <- "black"` and `colors[colors==1] <- "blue"`. Then use `bg=colors` and `fg=colors`. Might be easier to understand what is going on in this case :) – Karolis Koncevičius Nov 23 '14 at 19:56