-
Notifications
You must be signed in to change notification settings - Fork 632
Description
I'm trying to make a plot with plotly that have colors representing some class (factor ff in my example) and the size representing the population size (column ss in my example). I've posted on stackoverflow first here which got me further but I couldn't completely fix it and I think it's a bug.
Here is a reproductive example:
set.seed(123)
dd <- data.frame(
xx = rnorm(10),
yy = rnorm(10),
ff = as.factor(c("a","b","c","a","b","c","a","a","b","c")),
ss = round(runif(10, 100,1000))
)
dd2 <- dd
dd2 <- rbind(dd2, data.frame(xx=-.5, yy=1.5, ff="d", ss=50))
dd3 <- dd2
dd3 <- rbind(dd3, data.frame(xx=.5, yy=1.5, ff="d", ss=100))
I prepare 3 data.frame. The first one (dd
) is the basic one. The second one (dd2
), I add only one observation with a tiny size and a unique factor. He's alone in it's class. The last one (dd3
), I add a friend to the last observation from dd2
. Plotting works on dd
and dd3
but not dd2
(see below).
pp <- plot_ly(data = dd,
x = ~xx,
y = ~yy,
size= ~ss ,
hoverinfo = 'text', text = ~ss,
color = ~ff)
add_markers(pp,mode = "markers",
marker = list(sizeref = 3,
sizemode= "area"))
pp2 <- plot_ly(data = dd2,
x = ~xx,
y = ~yy,
size= ~ss ,
hoverinfo = 'text', text = ~ss,
color = ~ff)
add_markers(pp2,mode = "markers",
marker = list(sizeref = 3,
sizemode= "area"))
pp3 <- plot_ly(data = dd3,
x = ~xx,
y = ~yy,
size= ~ss ,
hoverinfo = 'text', text = ~ss,
color = ~ff)
add_markers(pp3,mode = "markers",
marker = list(sizeref = 3,
sizemode= "area"))
The size of observation 11 (factor d
) is way bigger than it should in comparison with other class for plot 2. But as soon as we add a new observation in the same class, everything seems fix.