Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Problems with Scatter 3d Axes ranges and labels

Hello everyone,

I am trying to plot my multilevel data with a 3D scatter plot. My data is from an experiment sampling experiment where people completed a questionnaire every day for a month about their motivational focus and success. I have 59 subjects and data completed every day over the course of a month. As an example, I want to plot each subjects’ data with a different coloured line showing their daily levels of promotion success over the course of the 30 days of data collection. I was able to plot this information but my Day (i.e, x-axis) has a minimum range of -10, which is not possible as my minimum for that variable is 1. Moreover, my Promotion Focus variable is being depicted with a range of 0 to 0.04, but this variables has a range of 0 to 100. I would like my axes to reflect the actual ranges of my data and I would like to label these axes. I cannot figure out how to do either. I want the following labels, X = Days, Y = Promotion Focus, Z = Subs.

Below is my code as well as a picture of my plot and a picture of how some of my data are organized.

Any help would be much appreciated! Thanks in advance.

– J.A. Hughes

dens <- with(df, tapply(Days, INDEX = Subs, density))
data <- data.frame(
x = unlist(lapply(dens, “[[”, “x”)),
y = unlist(lapply(dens, “[[”, “y”)),
Subs = rep(names(dens), each = length(dens[[1]]$x)))

plot_ly(data, x = ~x, y = ~y, z = ~Subs, type = ‘scatter3d’, mode = ‘lines’, color = ~Subs)