Programming with R

How-To Tutorials Tips - R Programming for Humans

One-line Code using viridis for How to change the color scale in ggplot plots

This is a small code snippet to explain how to change the color scale of a ggplot. Continuous Scale Package: viridis Function: scale_fill_viridis_c() (since it’s a continuous scaled value) library(dplyr) library(ggplot2) library(viridis) mtcars %>% tibble::rownames_to_column('Car') %>% tidyr::separate('Car',c('Brand','Model'), remove = F) %>% group_by(Brand) %>% summarize(avg_mpg = mean(mpg)) %>% ggplot() + geom_bar(aes(reorder(Brand,avg_mpg),avg_mpg, fill = avg_mpg), stat = 'identity') + scale_fill_viridis_c() + theme_minimal() + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs( title = 'How to arrange Ggplot Bar plot', x = 'mpg') Discrete Scale Package: viridis Function: scale_fill_viridis_d() (since it’s a discrete scaled value)

How to arrange ggplot (barplot) bars in ascending or descending order

One of the reasons you’d see a bar plot made with ggplot2 with no ascending / descending order - ordering / arranged is because, By default, ggplot arranges bars in a bar plot alphabetically. But most of the times, it would make more sense to arrange it based on the y-axis it represents (rather than alphabetically). It could be your month-wise time series or high-medium-low bars - these are some examples where an alphabetically-sorted bar chart wouldn’t make sense in fact would hinder the process of data communication.

How to scrape Zomato Restaurants Data in R

Zomato is a popular restaurants listing website in India (Similar to Yelp) and People are always interested in seeing how to download or scrape Zomato Restaurants data for Data Science and Visualizations. In this post, We’ll learn how to scrape / download Zomato Restaurants (Buffets) data using R. Also, hope this post would serve as a basic web scraping framework / guide for any such task of building a new dataset from internet using web scraping.

Combining the power of R and Python with reticulate

R + Py In the word of R vs Python fights, This is a simple (could be called, naive as well) attempt to show how we can combine the power of Python with R and create a new superpower. Like this one, If you have watched The Incredibles before! About this Dataset This dataset contains a bunch of tweet that came with this tag #JustDoIt after Nike released the ad campaign with Colin Kaepernick that turned controversial.