Johns Inos
Johns Inos

Reputation: 27

dplyr is not recognising column name

I am trying to draw the graph on ChannelTitle but the dplyr is not recogninsing the column even if the column is present in the data frame

Code:

videos_year %>% count(channelTitle) %>% arrange(desc(n)) %>%
mutate(channelTitle = reorder(channelTitle,n)) %>% head(10)%>%
ggplot(aes(channelTitle,n)) +
geom_col() +
scale_x_discrete() +
coord_flip() +
ggtitle(label = 'Top 10 chennels with most video uploads') +
xlab(label = 'Channel name') +
ylab(label = 'Number of videos') +
labs(fill = 'Ratio to the total video posted')

Upvotes: 0

Views: 753

Answers (1)

akrun
akrun

Reputation: 887241

The %>% link was missing between the head and ggplot, thus ggplot didn't get the data part (It is possible that the head was used as diagnostic purpose and then forgot to connect the plot part)

videos_year %>% 
   count(channelTitle) %>%
   arrange(desc(n)) %>%
   mutate(channelTitle = reorder(channelTitle,n)) %>%  
  ggplot(aes(channelTitle,n)) +
   geom_col() +
   scale_x_discrete() +
   coord_flip() +
   ggtitle(label = 'Top 10 chennels with most video uploads') +
   xlab(label = 'Channel name') +
   ylab(label = 'Number of videos') +
   labs(fill = 'Ratio to the total video posted')

Upvotes: 4

Related Questions