我正在尝试创建一个气泡图,在x和y轴上绘制2个变量X和Y.有一个第三个变量,Size(我用圆圈/气泡的大小表示)和第四个变量(Store Type,我用颜色表示)。
plot_ly似乎是在颜色范围内缩放气泡(因此应该具有相似大小的气泡实际上非常不同)。
我想在尺寸方面相对于彼此缩放所有气泡,无论存储类型或颜色如何。我正在使用RStudio,截至2009年6月23日的最新版本
以下是数据集:
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"))
...这是我目前的代码:
plot_ly(data = q, x = q$X, y = q$Y, text = paste("Size: ", q$Size), mode = "markers", color = q$Store, size = q$Size)
提前感谢您的帮助!