0

I am trying to create a bubble chart that plots 2 variables, X and Y, on the x and y axes. There is a 3rd variable, Size (which I am indicating with the size of the circle/bubble), and a 4th variable (Store Type, which I am indicating with color).

plot_ly appears to be scaling the bubbles within color (so that bubbles that should be of similar size are actually very different).

I would like to scale all the bubble relative to each other in terms of Size, regardless of Store Type or Color. I am using RStudio, most recent version as of 6/23/2017

Here is the data set:

structure(list(Code = 1:16, Store = c("A", "B", "B", "B", "B", 
"B", "B", "B", "B", "B", "B", "B", "H", "H", "H", "L"), X = c(0.551644853, 
0.475211345, 0.507242364, 0.439768021, 0.46672606, 0.424724417, 
0.431189134, 0.456000812, 0.422705703, 0.412122806, 0.389925153, 
0.466706775, 0.541410342, 0.580674207, 0.533852255, 0.445491296
), Y = c(0.937149903, 0.250231202, 0.434706987, 0.500365364, 
0.342481711, 0.199052594, 0.18707338, 0.107246187, 0.109985903, 
0.157119571, 0.10706856, 0.069265636, 1.316429676, 0.703730168, 
0.379612334, 1.728825132), Size = c(2642.3635, 2177.152838, 1530.361042, 
1084.561203, 1057.180728, 1021.145556, 610.5342105, 449.325566, 
311.9607609, 288.4075641, 211.5126293, 190.3996606, 2853.952619, 
2286.511829, 973.8094512, 332.2424444)), .Names = c("Code", "Store", 
"X", "Y", "Size"), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, 
-16L), spec = structure(list(cols = structure(list(Code = structure(list(), class = c("collector_integer", 
"collector")), Store = structure(list(), class = c("collector_character", 
"collector")), X = structure(list(), class = c("collector_double", 
"collector")), Y = structure(list(), class = c("collector_double", 
"collector")), Size = structure(list(), class = c("collector_double", 
"collector"))), .Names = c("Code", "Store", "X", "Y", "Size")), 
    default = structure(list(), class = c("collector_guess", 
    "collector"))), .Names = c("cols", "default"), class = "col_spec"))

...and here is my current code:

plot_ly(data = q, x = q$X, y = q$Y, text = paste("Size: ", q$Size), mode = "markers", color = q$Store, size = q$Size)

Thanks in advance for your help!

user2621147
  • 111
  • 3
  • 10

0 Answers0