Linked Questions

Popular Questions

I'm making a scatterplot with two traces using Plotly 4.10.2, R 4.3.1, RStudio 2023.06.1 Build 524. One trace is a point set and the other is a best fit line.

m1 <- lm(dt$d50 ~ dt$r501b3grange1)
m <- list(l = 60, r = 60, b = 60, t = 60, pad = 10)
fig <- plot_ly(dt, x = ~r501b3grange1, y = ~d50, 
               type = "scatter", 
               mode = "markers",
               text = ~`Image`,
               name = paste0("n = ", nrow(dt))) %>%
  
  layout(xaxis = list(title = "Point layer median thickness (inches, 1 ft ball, 3 ft grid)"),
         yaxis = list(title = "SAM minor axis d50 (g11 subset (All 57), inches)"),
         font = list(size = 25, color = "black"),
         margin = m) %>%
  
  add_trace(dt, x = ~r501b3grange1, y = predict(m1), name = paste0("y = ", 
                                                              round(summary(m1)$coefficients[[1]],2), " + ", 
                                                              round(summary(m1)$coefficients[[2]],2), "x", "\n",
                                                              "R^2 = ", round(as.numeric(summary(m1)[8]),2)),
            type = "scatter",
            mode = "lines")

fig

enter image description here

I want to make the markers bigger. But when I try adding a marker size to the first trace:

m1 <- lm(dt$d50 ~ dt$r501b3grange1)
m <- list(l = 60, r = 60, b = 60, t = 60, pad = 10)
fig <- plot_ly(dt, x = ~r501b3grange1, y = ~d50, 
               type = "scatter", 
               mode = "markers",
               marker = list(size = 10),
               text = ~`Image`,
               name = paste0("n = ", nrow(dt))) %>%
  
  layout(xaxis = list(title = "Point layer median thickness (inches, 1 ft ball, 3 ft grid)"),
         yaxis = list(title = "SAM minor axis d50 (g11 subset (All 57), inches)"),
         font = list(size = 25, color = "black"),
         margin = m) %>%
  
  add_trace(dt, x = ~r501b3grange1, y = predict(m1), name = paste0("y = ", 
                                                              round(summary(m1)$coefficients[[1]],2), " + ", 
                                                              round(summary(m1)$coefficients[[2]],2), "x", "\n",
                                                              "R^2 = ", round(as.numeric(summary(m1)[8]),2)),
            type = "scatter",
            mode = "lines")

fig

enter image description here

It adds markers to my best-fit line even though I have mode = "lines". I also tried using two add_trace statements rather than putting the first trace in the main plot_ly call, and got the same thing. Is this a bug?

Here is my data:

> dput(dt$d50)
c(2.191258065, 4.371259836, 4.163834921, 4.299901482, 0.721296517, 
0.806656288, 0.838300519, 2.123984458, 1.281270095, 1.271034705, 
1.126324259, 2.158535202, 0.811873646, 0.997379781, 0.791658847, 
0.865206465, 1.697433187, 1.306820106, 1.002612879, 0.932092299, 
1.741705726, 1.546688167, 1.408641227, 0.922844563, 0.845056924, 
0.997727831, 1.102327201, 1.120945941, 1.092093241, 1.182791188, 
1.303034055, 1.200149608, 1.051766949, 0.917999368, 0.879761687, 
0.25661637, 0.367374289, 0.451367428, 0.594794813, 0.412664784, 
0.326505198, 0.343620551, 0.441396171, 0.475386025, 0.400242695, 
0.374735446, 0.386719965, 0.312585107, 3.261716671, 3.292011578, 
0.767037605, 1.651888689, 1.193666161, 1.934104802, 2.286671289, 
1.43194983, 1.611017108)

> dput(dt$r501b3grange1)
c(1.09698951244354, 3.16094923019409, 2.79072117805481, 3.07730960845947, 
0.744107246398926, 1.22431325912476, 1.53918492794037, 1.52391850948334, 
0.751307666301727, 0.827914595603943, 1.34772574901581, 1.02658534049988, 
0.776823580265045, 0.762321770191193, 1.20416533946991, 0.986024975776672, 
1.5238938331604, 1.06575691699982, 1.04620349407196, 1.24733889102936, 
0.65419340133667, 0.705933749675751, 0.824617326259613, 0.979621589183807, 
1.15843141078949, 0.93364292383194, 0.818296492099762, 0.993945062160492, 
0.955138683319092, 0.853289723396301, 0.850569367408752, 0.850764274597168, 
0.663198113441467, 0.516988277435303, 0.539037942886353, 0.751503467559814, 
0.677738070487976, 0.792271614074707, 0.792271614074707, 0.627113521099091, 
0.584987282752991, 0.684955239295959, 0.77651035785675, 0.729957222938538, 
0.848376214504242, 0.74308979511261, 0.549346268177032, 0.6502605676651, 
2.18274283409119, 2.94228267669678, 0.680980920791626, 1.51205325126648, 
0.92967689037323, 1.24754667282104, 1.08400869369507, 0.809762358665466, 
0.843399584293365)

Related Questions