0

I want to create a histogram, my data is stored in a variable Z. Calling hist(Z) is showing an error. I tried changing Z to numeric but it is still showing errors:

Z=as.numeric(Z)
 Error: (list) object cannot be coerced to type 'double'

year <- c(2010, 2011, 2012, 2013)
disconnected_ppl <- c(116, 54, 310, 110)
df <- data.frame(year=year, disconnected_ppl=disconnected_ppl)
df

year      disconnected_ppl
2010      116
2011       54
2012      310
2013      110

I want to create a histogram of year on xlab and disconnected_ppl on ylab. Each bar plot should be mentioned by the years and names on both the axis but I got the graph in this way:

enter image description here

As am new to R can you please suggest me which is the right option to choose histograms or bar plot?

Bowdzone
  • 3,827
  • 11
  • 39
  • 52
arshia
  • 65
  • 1
  • 1
  • 6
  • 1
    Are you sure you want a histogram? Or do you mean a barplot? – Developer Oct 29 '15 at 19:37
  • It is very difficult to provide help without looking at some data and your code. Please see the link here regarding posting a reproducible example in `R` - http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Satya Oct 29 '15 at 19:48

1 Answers1

0

Maybe you could try this?

year <- c(2010, 2011, 2012, 2013)
disconnected_ppl <- c(116, 54, 310, 110)
df <- data.frame(year=year, disconnected_ppl=disconnected_ppl)
barplot(df$di,df$year, xlab = "Year", ylab = "disconnected_ppl", names=c(2010, 2011, 2012, 2013))

Or in ggplot:

install.packages("ggplot2")
library(ggplot2)
qplot(year, data=df, geom="bar", weight=disconnected_ppl, ylab="disconnected_ppl")
Developer
  • 917
  • 2
  • 9
  • 25