-1

Hey I'm relatively new to R and I have the following problem i could not solve using the search function. I have this excel file i created with data form world bank. Its a simple year and country gdp sheet with 3 countries Switzerland, Burkina Faso and the United States. The converted file in csv looks like this

year;Burkina Faso ;Switzerland;United States
1990;351.9793229;38332.15172;23954.47935
2000;226.4759814;37813.23426;36449.85512
2007;475.1100122;63223.46778;48061.53766
2008;569.7612784;72119.56087;48401.42734
2009;552.7455521;69672.00471;47001.55535
2010;575.4464527;74276.71842;48373.87882
2011;666.8402783;87998.44468;49790.66548
2012;673.8227;83164.38795;51450.1223
2013;699.0452847;84658.88768;52787.02695
2014;705.1464113;85814.58857;54598.55069
2015;615.592225;80989.84024;56207.03675
2016;649.7304837;78812.65069;57466.78711

I tried to plot it with ggplot2 the following way:

qplot(year, Switzerland, data = DATA_WORLD_CSV, xlab= "Year", geom = c("point", "smooth"))

but I always get an error message and I don't know why. Also does anyone have an idea how to get those 3 countries into one plot. Thanks in advance

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
macro123
  • 1
  • 2
  • You need to load your data into R, type ? read.table for help – Cedric Oct 26 '17 at 18:14
  • 1
    This similar question may help: https://stackoverflow.com/questions/17983478/plot-variable-for-one-country-relative-to-another?rq=1 – Stedy Oct 26 '17 at 18:22
  • i did load it into R thats not the problem, the problem is i dont understand why I get an error message if I try to plot the above stated function with Burkina Faso and the USA, it works with Switzerland but not with the others – macro123 Oct 26 '17 at 18:27
  • it would help if you posted the error message you got – user5359531 Oct 26 '17 at 19:14

1 Answers1

0

I'm guessing the error may be because you're trying to plot Burkina Faso and the United States by doing something like this:

qplot(year, Burkina Faso, data = DATA_WORLD_CSV, xlab = "Year", geom = c("point", "smooth"))

This will fail because of the spaces in the country name — same with "United States". Behind the scenes, ggplot2 will convert your column names by replacing the spaces with periods. So, instead, try:

qplot(year, Burkina.Faso, data = DATA_WORLD_CSV, xlab = "Year", geom = c("point", "smooth"))

To plot multiple lines on one graph, use ggplot() instead of qplot(). See for instance: Plotting two variables as lines using ggplot2 on the same graph

hangler
  • 390
  • 3
  • 10