Blog Archives

Fitting exponential decays in R, the easy way

September 9, 2018
By
Fitting exponential decays in R, the easy way

Exponential decays can describe many physical phenomena: capacitor discharge, temperature of a billet during cooling, kinetics of first order chemical reactions, radioactive decay, and so on. They are very useful functions, but can be tricky to fit in R: you’ll quickly run into a “singular gradient” error. Thankfully, self-starting functions provide an easy and automatic fix. Read on to...

Read more »

Curve fitting on batches in the tidyverse: R, dplyr, and broom

September 9, 2018
By
Curve fitting on batches in the tidyverse: R, dplyr, and broom

I recently needed to fit curves on several sets of similar data, measured from different sensors. I found how to achieve this with dplyr, without needing to define outside functions or use for-loops. This approach integrates perfectly with my usual dplyr and ggplot2 workflows, which means it adapts to new data or new experimental conditions with no changes. Here...

Read more »

An interactive map of mass shootings based on Shiny

March 15, 2018
By
An interactive map of mass shootings based on Shiny

“Four? That’s barely your average family murder-suicide!” - Anonymous American The United States saw 427 mass shootings in 2017, making a total of 2571 victims. That’s more than one shooting per day. Why don’t you hear about them on the news every day? Or conversely, if they are so common, why did the recent shooting in Las Vegas or the night...

Read more »

How to add Google Analytics to a Shiny application

February 21, 2018
By

I recently wanted to add a Google Analytics tracker to a Shiny dashboard, and I found that the official documentation doesn’t explain how to include “Global Site Tag” tracking code, which seems to be the current default setting in Analytics. The process is simple, we just have to include the tracking code as an HTML snippet in ui.R. The...

Read more »

How to change the number of breaks on a datetime axis with R and ggplot2

How to change the number of breaks on a datetime axis with R and ggplot2

It took me a surprising amount of time to find how to change the tick interval on ggplot2 datetime axes, without manually specifying the date of each position. The solution is surprisingly simple and clear once you know the syntax: scale_x_datetime(date_breaks = "12 hours") This places a break every 12 hours. The interval can be any value accepted by the scales...

Read more »

Search R-bloggers

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)