数据科学与R语言生物信息学R语言与统计分析

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

2020-03-07  本文已影响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
上一篇 下一篇

猜你喜欢

热点阅读