Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
An example script that plots a chart in ggplot2 using data downloaded from Eurostat.
# This script plots the youth unemployment rate in EU countries.
# Note that there are time series breaks and some values are
# estimated. This is shown in the 'flag' column but not on the chart.
# To get the data, follow this bookmarked link and download the data as csv:
# http://appsso.eurostat.ec.europa.eu/nui/show.do?query=BOOKMARK_DS-055628_QID_605AF573_UID_-3F171EB0&layout=TIME,C,X,0;SEX,L,Y,0;GEO,B,Y,1;S_ADJ,L,Z,0;AGE,L,Z,1;INDICATORS,C,Z,2;&zSelection=DS-055628AGE,Y_LT25;DS-055628INDICATORS,OBS_FLAG;DS-055628S_ADJ,SA;&rankName1=AGE_1_2_-1_2&rankName2=S-ADJ_1_2_-1_2&rankName3=INDICATORS_1_2_-1_2&rankName4=TIME_1_0_0_0&rankName5=SEX_1_2_0_1&rankName6=GEO_1_2_1_1&sortC=ASC_-1_FIRST&rStp=&cStp=&rDCh=&cDCh=&rDM=true&cDM=true&footnes=false&empty=false&wai=false&time_mode=ROLLING&time_most_recent=false&lang=EN&cfo=%23%23%23%2C%23%23%23.%23%23%23
library(ggplot2)
library(scales)
library(zoo)
youth_unemployment <- read.csv('une_rt_q_1_Data.csv')
youth_unemployment$Value <- as.numeric(as.character(youth_unemployment$Value))
youth_unemployment$TIME <- as.yearqtr(as.character(youth_unemployment$TIME))
# Only include data since 2000
youth_unemployment <- subset(youth_unemployment, TIME >= as.yearqtr('2000 Q1'))
youth_unemployment$TIME <- as.Date(youth_unemployment$TIME)
# Shorten name for Germany
levels(youth_unemployment$GEO_LABEL)[levels(youth_unemployment$GEO_LABEL)==
'Germany (until 1990 former territory of the FRG)'] <-
'Germany'
png('youth_unemployment2.png', width=900, height=600)
ggplot(youth_unemployment, aes(x=TIME, y=Value, colour=SEX, group=SEX)) +
facet_wrap(~ GEO_LABEL) +
geom_line() +
theme_bw() +
xlab('Year') +
ylab('Youth unemployment rate') +
scale_x_date(labels = date_format("%y")) +
theme(legend.title=element_blank())
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment