Skip to content

R for Journalists

Unlock the power of R

  • What Is R?
  • R for Rob
  • GitHub
  • Twitter
  • Etsy
  • Home
  • 2017
  • December
  • 11
  • R for Absolute Beginners

R for Absolute Beginners

Posted on December 11, 2017 By Rob
Learn

 

On Tuesday I gave a workshop at the Data Journalism UK conference, run by Paul Bradshaw.

This was the worked example for absolute beginners that we went through.

If you’ve never looked at R before and want to run some R code, load up this page , copy the following in step by step and hit ‘Run’:

#1. Print Hello world to the console
print("Hello, world!")

#2. Do some maths

2+2
4*5
(4+5) / 3

#3. Set some variables

var <- "My variable!"
var
my_name <- "Nicholas"

my_number <- 2
second_number <- 5
product <- my_number * second_number
product

#4. take a look at a data frame

mtcars
str(mtcars)
rownames(mtcars)

mtcars$cyl

mtcars[1,]
mtcars[1,5]

#5. perform some functions

#a) create a data frame of 100 random numbers

our_df <- data.frame(runif(n = 100))

#b) name the rows
colnames(our_df) <- "number"

#c) round the numbers

our_df$number <- round(our_df$number,2)

#d find the average of the numbers
mean(our_df$number)


#6. plot a graph of the numbers
#install the package if you haven't already
install.packages("ggplot2")
library(ggplot2)

p <- ggplot(data = our_df, aes(x = number, y = number)) + geom_point()
p

p2<- ggplot(data = our_df, aes(x = number, y = runif(n = 100))) + geom_point() + ggtitle("100 random numbers")
p2

p3 <- ggplot(data = our_df, aes(x = number, y = runif(n = 100), color = runif(n = 100))) + geom_point() + ggtitle("100 random numbers")
p3

There were presentations from various people in data journalism in Britain, which you can take a look at here.

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook

Related

Tags: beginner rstats

Post navigation

❮ Previous Post: Road accidents in November
Next Post: How to Use googlesheets to Connect R to Google Sheets ❯

Recent Posts

  • I’ve moved my blog over to Substack
  • How to plot a large rural area using Ordnance Survey data in R
  • Check the COVID-19 vaccination progress in your area
  • Let R tell you what to watch on Netflix
  • Sentiment analysis of Nineteen-Eighty-Four: how gloomy is George Orwell’s dystopian novel?

Archives

  • April 2022
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • February 2020
  • December 2019
  • November 2019
  • October 2019
  • April 2018
  • March 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016

Categories

  • Geospatial data
  • Landmark Atlas
  • Learn
  • See
  • Seen Elsewhere
  • Site
  • Uncategorized

Copyright © 2025 R for Journalists.

Theme: Oceanly by ScriptsTown