您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页交互式可视化plotly之基本图绘制

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

来源:伴沃教育

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

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务