R中的情节:通过布局向表面区域图表添加标签?

时间:2016-11-30 21:58:08

标签: r plotly surface

我正在使用表面积图表,我想知道如何更改标签,因为这个过程似乎与平面图不同,所以我无法绕过如何布置它们的布局。我收到一条警告信息,但我看到标题标签已经通过,想知道如何让X轴和Y轴改变。下面是我使用内置数据集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'

编辑关注:

将以下答案发布到最热门的问题,但作为后续内容,我如何为刻度线添加值?我假设有一种方法可以将序数值的列表向量输入到诸如c(“0”=“星期日”,“1”=“星期一”......)之类的刻度中。这准确吗?

感谢帮助!!!

1 个答案:

答案 0 :(得分:0)

如果有人需要,可以从不同的帖子中找到答案。我想知道如何将特定月份和工作日添加到刻度线?

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