Skip to content

Instantly share code, notes, and snippets.

View davidhen's full-sized avatar

David Henderson davidhen

View GitHub Profile
I think you need to reshape your data to tidy format so there are two variables (columns) for the drugs: "drug" and "value".
Could try...
```{r}
library(tidyr)
output <-
AnalysData %>%
gather(key = "drug", value = "value", Overallpresc:BroadSpecpresc) #This will work if your 3 drug columns are side by side
group_by(DataZone2011, drug) # Note we are grouping by the newly created "drug" variable as well
# Load the packages we’re going to be using:
# Alongside the usual stuff like tidyverse and magrittr, we’ll be using rvest for some web-scraping, jsonline to parse some JSON, and extrafont to load some nice custom fonts
needs(tidyverse, magrittr, rvest, jsonlite, extrafont)
# Before we go on, two things to note:
# First, on web scraping:
# You should always check the terms of the site you are extracting data from, to make sure scraping (often referred to as `crawling`) is not prohibited. One way to do this is to visit the website’s `robots.txt` page, and ensure that a) there is nothing explicitly stating that crawlers are not permitted, and b) ideally, the site simply states that all user agents are permitted (indicated by a line saying `User-Agect: *`). Both of those are the case for our use-case today (see https://www.ultimatetennisstatistics.com/robots.txt).
# And second, about those custom fonts:
@davidhen
davidhen / join-animations-with-gganimate.R
Created August 15, 2018 14:14 — forked from gadenbuie/join-animations-with-gganimate.R
Animated dplyr joins with gganimate
# Animated dplyr joins with gganimate
# * Garrick Aden-Buie
# * garrickadenbuie.com
# * MIT License: https://opensource.org/licenses/MIT
# Note: I used Fira Sans and Fira Mono fonts.
# Use search and replace to use a different font if Fira is not available.
library(tidyverse)
library(gganimate)
Function for plot of factor variables
Counts and summarises levels of a factor
Plots with `geom_lollipop()` from `ggalt` package
```{r}
library(ggplot2)
library(dplyr)
library(cowplot)
ubdc_palette <- c("#13AFD6", "#E6E600", "#F07329", "#35B14E", "#D7509A", "#2165AF",
"#BCD032","#866BAC", "#545A5D", "#7A8082", "#E2D988", "#628DB7",
# Packages
```{r}
library(dplyr)
library(ggplot2)
```
# Normal plot for one year
```{r}
social_care_df %>%