ggplot line chart generated from OECD.stat with unwanted vertical lines in the chart



I'm trying to follow the post on R-bloggers about sourcing the data from the OECD Statistics. I modified the code from the post to source the data I would like to visualise:



require(XML2R)
file <- "http://ift.tt/1NJk4wI"
obs <- XML2Obs(file)
tables <- collapse_obs(obs)
keys <- tables[["MessageGroup//DataSet//Series//SeriesKey//Value"]]
dates <- tables[["MessageGroup//DataSet//Series//Obs//Time"]]
values <- tables[["MessageGroup//DataSet//Series//Obs//ObsValue"]]
country_list <- keys[keys[,1]== "COU" | keys[,1]== "COUNTRY"]
country_list <- country_list[(length(country_list)*1/3+1):(length(country_list)*2/3)]
dat <- cbind.data.frame(as.numeric(dates[,1]),as.numeric(values[,1]))
colnames(dat) <- c('date', 'value')
dat$country <- c(country_list[1], country_list[cumsum(diff(dat$date) <= 0) + 1])
dat$value2 <- signif(dat$value,2)
head(dat)
dat <- dat[complete.cases(dat),]
library(ggplot2)
ggplot(dat) +
geom_line(aes(x = date,y = value, colour = country)) +
theme(axis.title = element_text(colour = 'black', face = 'bold', size = 12,
family = 'sans'),
axis.text = element_text(colour = 'black', size = 12),
plot.title = element_text(size = 17, face = "bold", colour = "black"),
panel.background = element_rect(fill = NA),
panel.grid.major = element_line(colour = 'gray', linetype = 'dotted'),
strip.background = element_rect(fill = NA, colour = NA),
strip.text = element_text(colour = 'black', face = 'plain', size = 13),
plot.background = element_rect(fill = NA, colour = 'black', size = 0.25))


However, the generated chart contains odd lines: ggplot with unwated lines I would like to know:



  1. Why the lines appeared?

  2. How can I remove them?


No comments:

Post a Comment