2

I'm testing the R project with a bubble graph. For this, I have the following csv file:

download result.csv file

I did this:

> mydata<-read.csv("~/Desktop/result.csv", header=TRUE)
> mydata

  month     sale    comm maxcomm savings
  1 23415960  706164  998457  292293
  2 21303842  870591  928084   57493
  3 22128502  644698  897262  252564
  4 23872123  800024 1047968  247944
  5 25880653  900984 1006359  105375
  6 26359929 1186594 1601646  415052

for the command below, I get the red bubble

symbols(mydata$sale, mydata$comm, circles=mydata$savings, bg="red")

and for the command below, I get the blue bubble

symbols(mydata$sale, mydata$comm, circles=mydata$maxcomm, bg="blue")

My goal is to integrate them both together (in one graph) so the red will be on top of the blue. (If there's any possibility to have the blue transparent - even better!)

enter image description here enter image description here

adhg
  • 8,947
  • 8
  • 51
  • 88

2 Answers2

4

Set add=TRUE:

symbols(mydata$sale, mydata$comm, circles=mydata$maxcomm, bg="blue")
symbols(mydata$sale, mydata$comm, circles=mydata$savings, bg="red", add=TRUE)

Take a look at rgb() or the ggplot function for transparent colors (referred to by alpha.

Señor O
  • 15,939
  • 2
  • 41
  • 43
2

There are a few ways of doing this, but staying within the base graphics package you can use the par() command and add plots on top of each other. Also, to control transparency, you can convert your colors to hexadecimal values (red is #FF0000, blue is #0000FF) and add two digits at the end represending the alpha transparency layer

symbols(mydata$sale, mydata$comm, circles=mydata$savings, bg="#FF0000")
par(new=TRUE)
symbols(mydata$sale, mydata$comm, circles=mydata$maxcomm, bg="#0000FF50")

This sets the transparency of the second symbol chart to 50% 1

Also see this related question for more detail: 2

Community
  • 1
  • 1
ano
  • 644
  • 4
  • 15