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

无人久伴 提交于 2019-12-13 02:09:02

问题


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://stats.oecd.org/restsdmx/sdmx.ashx/GetData/HEALTH_STAT/EVIE+EVIEFE00+EVIEFE40+EVIEFE60+EVIEFE65+EVIEFE80+EVIEHO00+EVIEHO40+EVIEHO60+EVIEHO65+EVIEHO80+EVIETOTA.EVIDUREV+EVIFHOEV+EVIHFEEV.POL+GBR+USA/all?startTime=1960&endTime=2013"
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:

I would like to know:
  1. Why the lines appeared?
  2. How can I remove them?

来源:https://stackoverflow.com/questions/29449377/ggplot-line-chart-generated-from-oecd-stat-with-unwanted-vertical-lines-in-the-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!