Send tweets from R: A very short walkthrough

There are a few reasons why you might want to send tweets from R. You might want to write a Twitter bot or – as in my case – you want to send yourself a tweet when a very long computation finishes. So, here I will run you through all the steps you have to take using– Twitter’s API and– the twitteR package written by Jeff Gentry The setup to send myself tweets is the following: I have my main twitter account and an additional account I am only using to tweet from R. I am following the additional account with my main account. On my phone’s Twitter app, my main account is logged in and notifications are activated only for the additional account. So, whenever I tweet something with the additional account, the new tweet pops up on my…
Original Post: Send tweets from R: A very short walkthrough

Get your tracks from the Strava API and plot them on Leaflet maps

Here is some updated R code from my previous post. It doesn’t throw any warnings when importing tracks with and without heart rate information. Also, it is easier to distinguish types of tracks now (e.g., when you want to plot runs and rides separately). Another thing I changed: You get very basic information on the track when you click on it (currently the name of the track and the total length). Have fun and leave a comment if you have any questions. options(stringsAsFactors = F) rm(list=ls()) library(httr)library(rjson)library(leaflet)library(dplyr) token <- “” # Functions ————————————————————— get.coord.df.from.stream <- function (stream.obj) {  data.frame(lat = sapply(stream.obj[[1]]$data, USE.NAMES = F, FUN = function (x) x[[1]]),             lon = sapply(stream.obj[[1]]$data, USE.NAMES = F, FUN = function (x) x[[2]]))} get.stream.from.activity <- function (act.id, token) {  stream <- GET(“https://www.strava.com/”,                path = paste0(“api/v3/activities/”, act.id, “/streams/latlng”),                query = list(access_token = token))  content(stream)}…
Original Post: Get your tracks from the Strava API and plot them on Leaflet maps

Where do you run to? Map your Strava activities on static and Leaflet maps.

So, Strava’s heatmap made quite a stir the last few weeks. I decided to give it a try myself. I wanted to create some kind of “personal heatmap” of my runs, using Strava’s API. Also, combining the data with Leaflet maps allows us to make use of the beautiful map tiles supported by Leaflet and to zoom and move the maps around – with the runs on it, of course. So, let’s get started. First, you will need an access token for Strava’s API. I found all the necessary information for this in this helpful “Getting started” post. As soon as you have the token, you have access to your own data. Now, let’s load some packages and define functions for getting and handling the data. For the get.activities() function, I adapted code from here. library(httr)library(rjson)library(OpenStreetMap)library(leaflet)library(scales)library(dplyr)token <- “”get.coord.df.from.stream <- function…
Original Post: Where do you run to? Map your Strava activities on static and Leaflet maps.

Substitute levels in a factor or character vector

I’ve been using the ggplot2 package a lot recently. When creating a legend or tick marks on the axes, ggplot2 uses the levels of a character or factor vector. Most of the time, I am working with coded variables that use some abbreviation of the “true” meaning (e.g. “f” for female and “m” for male or single characters for some single character for a location: “S” for Stuttgart and “M” for Mannheim). In my plots, I don’t want these codes but the full name of the level. Since I am not aware of any super-fast and easy to use function in base R (let me know in the comments if there is one), I came up with a very simple function and put this in my .Rprofile (that means that it is available whenever I start R). I called it…
Original Post: Substitute levels in a factor or character vector

Visualisation of Likert scale results

I wrote a function to visualise results of Likert scale items. Please find the function below the post. Here is an example plot: The function is called ‘plot.likert’ and takes the following arguments: – vec: The vector with the raw results – possible.values: A vector with all the possible values. This is sometimes important if not all possible responses were…
Original Post: Visualisation of Likert scale results

Troubles with cell labels in mosaic plots… and how to solve them.

Today I want to write about a solution to a quite specific problem. Suppose, you want to label cells in your ‘vcd’ package mosaic plots in a custom way. For example, we might want to use cell labels which indicate “too much” or “too few” cases (given your expected values). Such labels might be “+” and “-” (and maybe “++”…
Original Post: Troubles with cell labels in mosaic plots… and how to solve them.

Do basic R operations much faster in bash [Slightly off-topic]

R is great, and you can do a LOT OF stuff with it. However, sometimes you want to do really basic stuff with huge or a lot of files. At work, I have to do that a lot because I am mostly dealing with language data that often needs some pre-processing. Most of these operations are done much, much faster…
Original Post: Do basic R operations much faster in bash [Slightly off-topic]