如何可视化以下数据集?

时间:2018-06-27 14:00:51

标签: r data-visualization

我有以下数据集,可以用统计编程语言R复制:

library(data.table)
sheet1 <- data.table(userID = c('abc123', 'abc123', 'abc123', 'def456', 'def456'), 
           sessionID = c('1529665492722.251rq8', 
                         '1529922427795.g2k607go',
                         '1529931067235.0yw5eqfa6', 
                         '1529945600035.345m7ym1', 
                         '1529950171742.fhmkcj6l'),
           month = '6',
           totalpageviews = c('10', '15', '56', '23', '24'),
           pagePath = c('application/123', 'application/456', 'application/789', 'application/101112', 'application/131415'))

sheet2 <- data.table(userID = c('abc123', 'abc123'),
                     sessionID = c('1529665492722.251rq8', '1529922427795.g2k607go'),
                     eventCategory = c('x', 'x', 'c'),
                     eventAction = c('y', 'z', 'a'),
                     pagePath = c('application/123', 'application/123', 'application/123'))

sheet1和sheet2具有共同的字段,即userID和sessionID。我想将数据提供给没有电子表格经验的同事。如何以未经训练的眼睛可以提取见解的方式可视化数据?

我愿意探索不同的选择。它可以是R,excel或Power BI等BI工具。

1 个答案:

答案 0 :(得分:1)

学习需要一些时间,但是ggplot2可以带给您很多帮助。检出http://r4ds.had.co.nz/data-visualisation.html

如果您更喜欢当前使用的分类变量,则还可以将sessionID转换为有序或数字形式,以查看时间序列趋势。

这是我可能会形象化您当前拥有的东西:

# install.packages('dplyr')
library(dplyr)
sheet <- full_join(sheet1, sheet2)

# install.packages('ggplot2') # visualization package
library(ggplot2)
# all data; bars including NAs and Event category/action
(p <- ggplot(sheet) +
  geom_col(aes(sessionID, totalpageviews, fill = interaction(eventCategory, eventAction)), position = 'dodge') +
  guides(fill = guide_legend(title = 'Event Category.Action')) +
  theme(axis.text.x = element_text(angle = -30, hjust = .3)))

# just application/123
(p2 <- p %+% (sheet %>% filter(pagePath == 'application/123')))

# just page views and page path
(p3 <- ggplot(sheet %>% select(totalpageviews, pagePath)) +
  geom_bar(aes(totalpageviews, pagePath), stat = 'identity', fill = scales::muted('blue')))