0

I am trying to visualize the population per year in R with a ggplot.

I would like to have years on the x axis and population on the Y axis.

Have the following code:

    df <- read.csv("http://www.statistikdatabasen.scb.se/sq/13965", header=TRUE, sep=",", na.strings="NA", dec=".",stringsAsFactor=F)

library(ggplot2)
ggplot(df, aes(x=year))+geom_bar()

Any suggestions how i can proceed?

Biffen
  • 6,249
  • 6
  • 28
  • 36
Martin598
  • 1,491
  • 3
  • 13
  • 20
  • First, please read (1) [how do I ask a good question](http://stackoverflow.com/help/how-to-ask), (2) [How to create a MCVE](http://stackoverflow.com/help/mcve) as well as (3) [how to provide a minimal reproducible example in R](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610). Then edit and improve your question accordingly. I.e., provide input data & the expected output. – lukeA May 14 '16 at 13:03

2 Answers2

1

From documentation of ggplot:

If you want the heights of the bars to represent values in the data, use stat="identity" and map a value to the y aesthetic.

ggplot(df, aes(year,Population)) + geom_bar(stat="identity")
mqpasta
  • 960
  • 3
  • 14
  • 38
0

You are missing the identity in the geom_bar

Try this:

ggplot(df, aes(x= year, y=Population)) + geom_bar(stat="identity", fill="dark blue")

Then I would suggest to fix the axis.

Saul Garcia
  • 890
  • 2
  • 9
  • 22