下面是我的代码的一个小示例,它显示了这个问题.
我希望生成的点大小是从offset
中的值派生出来的.
为了得到合理的值,我会在计算之前进行计算.
这些值的范围约为2-20.
但是,打印中的点大小完全不正确.
此外,图例中的点大小不一致.
library(plotly)
offset_plot_colors <- c('#845EC2', '#D65DB1', '#FF6F91', '#FF9671', '#FFC75F', '#F9F871')
df <- data.frame(
insert_position = c(1, 2, 3, 4, 5, 6,
1, 2, 3, 4, 5, 6,
1, 2, 3, 4, 5, 6,
1, 2, 3, 4, 5, 6),
experiment = c(100, 100, 100, 100, 100, 100,
101, 101, 101, 101, 101, 101,
102, 102, 102, 102, 102, 102,
103, 103, 103, 103, 103, 103),
sensor_position = c("s1", "s2", "s3", "s4", "s5", "s6",
"s1", "s2", "s3", "s4", "s5", "s6",
"s6", "s1", "s2", "s3", "s4", "s5",
"s5", "s6", "s1", "s2", "s3", "s4"),
offset = c( -0.10187856, -0.11539658, -0.01525474, 0.06469351, -0.13144734, 0.10990038
, -0.11939423, -0.12415050, -0.01897634, 0.06963700, -0.12348225, 0.11077662
, 0.09999526, -0.11111048, -0.13619725, -0.03287019, 0.05424941, -0.12881697
, -0.12830725, 0.09734471, -0.11105168, -0.12477904, -0.02409957, 0.06817639)
)
# calc size of dot
df$size <- abs(df$offset) * 150
offset_plot1 <- plot_ly(df,
x = ~experiment, y = ~insert_position,
color = ~sensor_position,
colors = offset_plot_colors,
marker = list(size = ~size, opacity=1)
) %>%
add_markers(
text = ~paste("Sensor:", sub(".*_", "", sensor_position), "<br>Offset:", round(df$offset, digits = 2), "<br>size:", size),
hoverinfo = "text"
)
offset_plot1 <- offset_plot1 %>% layout(
title = "Offset vs Insert Position vs Experiment",
xaxis = list(title = "Experiment"),
yaxis = list(title = "Insert Position"),
legend = list(title = "Offset")
)
offset_plot1