Function

コメント・参照等
  • plotlyでチャートを作成する関数

FUN = f_plotly.r
function (datadf, col_x = 1, col_y = 2, col_text = NULL, type = c("scatter", "bar", "box", "heatmap", "histogram", "histogram2d", "histogram2dcontour", "pie", "contour", "scatterternary", "violin", "scatter3d", "surface", "mesh3d", "cone", "streamtube", "scattergeo", "choropleth", "scattergl", "splom", "pointcloud", "heatmapgl", "parcoords", "scattermapbox", "sankey", "table", "carpet", "scattercarpet", "contourcarpet", "ohlc", "candlestick", "scatterpolar", "scatterpolargl", "area"), mode = "lines+markers", 
    line_width = 1, maintitle = NULL, xaxistitle = NULL, yaxistitle = NULL, showlegend = T, hoverstyle = NULL) 
{
    type <- match.arg(type)
    titlefont <- list(size = 13, family = "Meiryo", color = "Black")
    tickfont <- list(family = "Meiryo", size = 13, color = "black")
    title <- list(title = maintitle, titlefont = "Meiryo", size = 13, color = "Black")
    xaxis <- list(title = xaxistitle, titlefont = "Meiryo", size = 13, color = "Black", showticklabels = T, tickangle = 0, tickfont = tickfont)
    yaxis <- list(title = yaxistitle, titlefont = "Meiryo", size = 13, color = "Black", showticklabels = T, tickangle = 0, tickfont = tickfont)
    lydata <- plot_ly(x = datadf[, col_x])
    for (ccc in col_y) {
        if (is.null(col_text)) {
            lydata <- lydata %>% add_trace(y = datadf[, ccc], name = colnames(datadf)[ccc], type = type, mode = mode, line = list(width = line_width))
        }
        else {
            lydata <- lydata %>% add_trace(y = datadf[, ccc], name = colnames(datadf)[ccc], type = type, mode = mode, line = list(width = line_width), text = datadf[, col_text])
        }
    }
    lydata <- lydata %>% layout(title = maintitle, titlefont = titlefont, xaxis = xaxis, yaxis = yaxis)
    lydata <- lydata %>% layout(showlegend = showlegend) %>% layout(plot_bgcolor = "rgba(0,0,0,0)") %>% layout(paper_bgcolor = "rgba(0,0,0,0)")
    if (!is.null(hoverstyle)) {
        lydata <- lydata %>% style(hoverinfo = hoverstyle)
    }
    return(lydata)
}