Problems with the schedule of years

The code ran in RStudio (version 0.98.1091, R 3.1.2) on a Mac since 10.10. Not enough reputation to submit the image, so please run the R-code.

My problem has to do with the way my plots display my points as dots instead of bars. I have a dataframe as shown below.

ebola = c(0,26,1,2,0,2,0,0)
dengue = c(474,1943,2209,963,1498,1720,1360,1364)
rabies = c(1336,1353,1938,3116,908,1264,2499,1130)
year = c("2007","2008","2009","2010","2011","2012","2013","2014")
virus_data_by_year = data.frame(year,ebola,dengue,rabies)
virus_data_by_year

      

The above functions work fine. My problem arises when I try to speak let say year vs. ebola with the following function:

with(virus_data_by_year,plot(year,ebola,type="p",xlab="year",ylab="ebola"))

      

Even though I am using point element in my type argument it shows

bad graph

My problem with the above chart is that it shows my data as horizontal bars and not points. When I change the type argument in the string, it still displays the same graph instead of dots connected by a string as shown below.

plot (year,ebola, type = "b")

      

good graph

I can draw it fine if I draw the original two vectors so it seems like a data problem. Also, it is limited to year one because if I use the function below it still displays the graph graphically.

with(virus_data_by_year,plot(ebola,dengue,type = "b"))

      

+3


source to share


1 answer


Convert year

to a valid date format year = as.Date(year, "%Y")

.



+1


source







All Articles