revenue <- read.csv("data/revenue.csv")
数据集放在了文章末尾,需要自取。
if(!require(plotly)) install.packages("plotly")
# 绘制柱状图
p <- plot_ly(revenue,y = ~本周,x = ~游戏名称,type = "bar",name = "本周")
p
p %>% add_trace(y = ~上周,name = "上周")
p %>%
add_trace(y = ~上周,name = "上周") %>%
layout(barmode = 'stack',
xaxis = list(title = ""),
yaxis = list(title = ""),
title = "游戏收入数据")
# 绘制箱线图
plot_ly(midwest, x = ~percollege, color = ~state, type = "box")
# 绘制散点图
plot_ly(midwest, x = ~percollege, y = ~perblack, color = ~state, type = "scatter")
# 绘制直方图
plot_ly(midwest, x = ~percollege, type = "histogram")
# 绘制密度图
plot_ly(midwest, x = ~percollege, type = "histogram", histnorm = "probability")
# 绘制热力图
plot_ly(z = ~volcano, type = "heatmap")