交互式可视化plotly之基本图绘制

作者: 生信编程日常 | 来源:发表于2020-03-07 22:50 被阅读0次

    Plotly是个交互式可视化的第三方库,可以实现R语言的交互可视化,用法与ggplot差不多,默认的颜色比ggplot好看很多,本文简单介绍一下Plotly的应用。

    首先安装并运行包

    install.packages("plotly")
    # 载入ggplot2包
    library(plotly)
    

    主要参数:
    plot_ly(data = data.frame(), type = NULL, name, color,
    colors = NULL, alpha = NULL)
    ploly主要通过type来控制是画boxplot,barplot,scatter plot还是其他;
    name:Values mapped to the trace's name attribute.即选中处追加的名字

    Boxplot

    library(plotly)
    fig <- plot_ly(iris, x = ~Petal.Length, color = ~Species, type = "box")
    fig
    
    image.png

    Scatter Plot

    fig <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length, color = ~Species)
    fig
    
    image.png

    barplot

    fig <-
      plot_ly(
      x = c("a", "b", "c"),
      y = c(20, 14, 23),
      name = "barplot",
      type = "bar",
      color = c("#FFA488", "#8CD790", "#00AAAA")
      )
      
      fig
    
    image.png

    lineplot

    x <- c(1:100)
    random_y <- rnorm(100, mean = 0)
    data <- data.frame(x, random_y)
    
    fig <- plot_ly(data, x = ~x, y = ~random_y, type = 'scatter', mode = 'lines')
    
    fig
    
    image.png

    欢迎关注~


    公众号二维码.jpg

    相关文章

      网友评论

        本文标题:交互式可视化plotly之基本图绘制

        本文链接:https://www.haomeiwen.com/subject/aaekdhtx.html