0
votes

I'm working with surface area charts in plotly and I'm wondering how to change the labels as the process seems different from flat charts so I'm having trouble wrapping my head around how they layout should be arranged. I'm getting a warning message but I see that the title label has gone through, wondering how to get the X axis and Y axis to change. Below is my reproducible code using he built in data set freeny:

#stack question for surface plot
library(plotly)
library(zoo)

#set data
master = freeny
master$year = round(as.numeric(row.names(master)))
master$month = sample(1:6, 39, replace=TRUE)
master$month = paste0("0",master$month)
master$date = as.Date(with(master, paste0(year,"-" ,month,"-" ,"28")))
master$weekday = weekdays(master$date)
master$month_year = as.yearmon(master$date)
master


#build matrix
matrix_d = xtabs(income.level ~ month_year + weekday, master)
matrix_d

#plot
p = plot_ly(z = ~matrix_d) %>% add_surface()
p


#label
 p = layout(p,              # all of layout's properties: /r/reference/#layout
                title = "income levels across month and weekdays", # layout's title: /r/reference/#layout-title
                xaxis = list(           # layout's xaxis is a named list. List of valid keys: /r/reference/#layout-xaxis
                  title = "weekday",     # xaxis's title: /r/reference/#layout-xaxis-title
                  showgrid = F        # xaxis's showgrid: /r/reference/#layout-xaxis-showgrid
                ),
                yaxis = list(           # layout's yaxis is a named list. List of valid keys: /r/reference/#layout-yaxis
                  title = "month_year"      # yaxis's title: /r/reference/#layout-yaxis-title
                ),
            zaxis = list(
              title = "income_level"
            ))
p


Warning message:
'layout' objects don't have these attributes: 'zaxis'
Valid attributes include:
'font', 'title', 'titlefont', 'autosize', 'width', 'height', 'margin', 'paper_bgcolor', 'plot_bgcolor', 'separators', 'hidesources', 'smith', 'showlegend', 'dragmode', 'hovermode', 'xaxis', 'yaxis', 'scene', 'geo', 'legend', 'annotations', 'shapes', 'images', 'updatemenus', 'ternary', 'mapbox', 'radialaxis', 'angularaxis', 'direction', 'orientation', 'barmode', 'bargap', 'mapType'

EDIT FOLLOWUP:

Posted the answer below to the top question but as a followup how would I add values to the tick marks? I'm assuming there is a way to feed a list vector of ordinal values to the ticks such as c("0" = "sunday", "1" = "Monday" . . . ). Is this accurate?

Appreciate the help!!!

1

1 Answers

0
votes

Found the answer from a different posting in case anyone ever needs it. I'm wondering though how to add the specific month and weekday to the tick marks?

p <- plot_ly(z = ~matrix_d) %>% add_surface() %>%
layout(title = 'income levels across month and weekdays',
       scene = list(xaxis = list(title = 'weekday'),
                    yaxis = list(title = 'month'),
                    zaxis = list(title = 'income_level')))

p