1

Assuming we have this reproducible dataframe:

set.seed(949494)

Rating_1 <- round(runif(50, 1, 5))
Rating_2 <- round(runif(50, 1, 5))
Rating_3 <- round(runif(50, 1, 5))
ID <- rep(c("H", "G"), 25)
Quality <- Rating_1 * Rating_2 * Rating_3

DF <- data.frame(ID, Rating_1, Rating_2, Rating_3, Quality)

We want to see this in a scatterplot with 3-axes:

# Plotly scatter3d plot
plot_ly(DF, x = ~Rating_1, y = ~Rating_2, z = ~Rating_3,
        color = ~Quality, type = "scatter3d", mode = "markers",
        marker = list(symbol = "circle")) %>%
  add_markers(text = ~paste("Quality:", Quality)) %>%
  layout(scene = list(xaxis = list(title = "Novel"),
                      yaxis = list(title = "Benefit"),
                      zaxis = list(title = "Feasible")),
         title = "Quality Of Ideas")

How can I make the circles increase in size based directly on the frequency? If there are multiple on the exact same spot, I'd like to see it based on the size of the circle.

Smuts94
  • 49
  • 7
  • You can add a frequency column to the data frame, then use `size` in Plotly. For example: `df2 <- group_by(DF, across(ID:Quality)) %>% mutate(Freq = dplyr::n())` and in Plotly `plot_ly(df2, x = ~Rating_1, y = ~Rating_2, z = ~Rating_3, color = ~Quality, type = "scatter3d", mode = "markers", size = ~Freq, marker = list(symbol = "circle"))` or dropping the `markers` while achieving the same outcome: `plot_ly(df2, x = ~Rating_1, y = ~Rating_2, z = ~Rating_3, color = ~Quality, type = "scatter3d", mode = "markers", size = ~Freq, symbol = I("circle"))` – Kat Jul 17 '23 at 16:04

0 Answers0