1
votes

I have count the values of a column with dplyr.

yelp_tbl %>% select(name) %>% count(name)

The resulting data looks like this:

# A tibble: 108,999 x 2
                                  name     n
                                  <chr> <int>
 1                    'do blow dry bar     1
 2                  'Round Table Tours     1
 3                      'S Hundehüttle     1
 4                           # 1 Nails     1
 5 #1 Cochran Buick GMC of Monroeville     1
 6    #1 Cochran Buick GMC of Robinson     1
 7   #1 Cochran Cadillac - Monroeville     2

Now I want to make a boxplot of the "n" column.

yelp_tbl %>% select(name) %>% count(name) %>% boxplot(n)

But I got this result:

Error in x[floor(d)] + x[ceiling(d)] : 
non-numeric argument to binary operator

Any Idea? Is it because of the function?

3
Thank you! If I try this I get: Error in if (use.cols) { : argument is not interpretable as logical - Hadsga
do you really need boxplot? Can you please double check, I think that barplot should be used with this kind of data - pogibas
A histogram/barplot is fine also, but there is the same problem. - Hadsga

3 Answers

1
votes

Pull the column out as a numeric vector and then do boxplot:

library(stringi)
df <- data.frame(name = stri_rand_strings(10000, 2, pattern = '[a-z]'))

df %>% select(name) %>% count(name) %>% pull(n) %>% boxplot()
#                                       ^^^^^^

enter image description here

0
votes

Try this (it's hard to know if it works without example data):

library(tidyverse)

yelp_tbl %>% 
    select(name) %>% 
    count(name) %>%
    ggplot(aes(name, n)) + 
        geom_bar(stat = "identity", position = "dodge")
0
votes

Try switching between x and y axis to see if it works the other way using boxplot(), or use a different function like ggplot() + geom_boxplot()

Example:

boxplot(yelp_tbl, aes(x = n, y = name)) 

or

yelp_tbl %>% ggplot(aes(n, name)) + geom_boxplot()