making a barchar using R / R markdown -


the code wrote in r setup section in r markdown was,

roaddataset <- read.csv("https://bitre.gov.au/statistics/safety/files/fatalities_june_2017.csv") data <- select(roaddataset, year, state) 

(this extract columns data set)

then barchart, wrote,

ggplot(data, aes(x=state, y=year)) +         geom_bar(stat = "identity") +         labs(x="state", y="year") 

this runs program successfully, however, y-axis shown in barchart diagram(not title ylab!) written strange words such "1e + 07"... not showing numbers "year" should 1989 2017. x-axis fine, displays names each states

is there anyway figure out? thanks!

i think you're after:

data$year<-as.factor(data$year)  p <- ggplot(data) p <- p + geom_bar(aes(x=year, y = ..count.., fill= state)) p <- p + scale_x_discrete("year", breaks=levels(data$year)) p <- p + theme(axis.text.x = element_text(angle = 45, hjust=1))  p 

here, ..count.. count of each state per year, plotted against year, , coloured state

enter image description here


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -