1

I don't know what is wrong with my code. but i get this error:

> Visitas_Por_Fuente %>% ggvis(~Campanas1, ~sessions) %>% layer_bars()
Error in .subset2(x, i, exact = exact) : subscript out of bounds

I just want to create a bar graphic, that shows how many sessions by source do we have.

I use this code (but 'im not seeing the graph):

i've a data.frame that contains the following types of data:

Visitas_Por_Fuente %>% ggvis(~Campanas1, ~sessions) %>% layer_bars()

And this is the output for the str() function on my data.frame:

Classes ‘tbl_df’, ‘tbl’ and 'data.frame':   4177 obs. of  8 variables:
$ date         : Date, format: "2014-09-01" "2014-09-01" "2014-09-01" ...
$ dayOfWeekName: chr  "Monday" "Monday" "Monday" "Monday" ...
$ userType     : chr  "New Visitor" "New Visitor" "New Visitor" "New Visitor" ...
$ source       : chr  "(direct)" "amazon.es" "bing" "col128.mail.live.com" ...
$ Medium       : chr  "(none)" "referral" "organic" "referral" ...
$ campaign     : chr  "(not set)" "(not set)" "(not set)" "(not set)" ...
$ sessions     : num  97 1 2 1 5 2 124 1 35 1 ...
$ Campanas1    : Factor w/ 7 levels "Adwords","Campañas",..: 3 5 6 4 5 7 6 7 5 5 ...

head(Visitas_Por_Fuente)

Source: local data frame [6 x 8]

    date dayOfWeekName    userType                   source   Medium  campaign    sessions    Campanas1
1 2014-09-01        Monday New Visitor             (direct)   (none) (not set)       97      Directo
2 2014-09-01        Monday New Visitor            amazon.es referral (not set)        1  Referencias
3 2014-09-01        Monday New Visitor                 bing  organic (not set)        2          SEO
4 2014-09-01        Monday New Visitor col128.mail.live.com referral (not set)        1        Email
5 2014-09-01        Monday New Visitor         eloi.go.com referral (not set)         5  Referencias
6 2014-09-01        Monday New Visitor         facebook.com referral (not set)        2 Social Media
4

1 回答 1

3

我认为解决方案与“整洁数据”一词有关。

脚步:

1.- 使用“Dplyr”中的“select”简化您的 data.frame:

Visitas_Por_Fuente3 <- select(Visitas_Por_Fuente, Campanas1, sessions)

2.- 用“reshape2”中的“melt”融化它:

Visitas_Por_Fuente6 <- melt(Visitas_Por_Fuente3)

3.- 用 ggvis 制作图表:

Visitas_Por_Fuente6 %>% ggvis(~Campanas1, ~value) %>% layer_bars()

笔记:

如果您只是尝试制作图表而不对其进行重塑,它将无法正常工作。

我不知道为什么。他们看起来和我一样,这里有 2 个 data.frames 的负责人:

A) Visitas_Por_Fuente3 - 无需重塑:

     Campanas1    sessions
1      Directo        97
2  Referencias        1
3          SEO        2
4        Email        1
5  Referencias        5
6 Social Media        2

B) Visitas_Por_Fuente6 - 重塑它:

     Campanas1 variable value
1      Directo sessions    97
2  Referencias sessions     1
3          SEO sessions     2
4        Email sessions     1
5  Referencias sessions     5
6 Social Media sessions     2

这是为什么?任何想法?

这就是我想要的,也得到了。但是,有没有办法为每列添加值?谢谢

在此处输入图像描述

于 2014-12-28T04:01:47.023 回答