0

I want to plot a line graph with continuous years on x axis from 1990 to 2005.

# I create a dataframe as below and try to plot as a line graph. 

year<-c(1990:2005)

num<-c(3,2,4,7,6,22,9,31,12,30,17,23,21,36,41,21)

df<-data.frame(year,num)

str(df)

library(ggplot2)

ggplot(data=df,aes(x=year,y=num)) + geom_line() + theme_bw() + ylab("Number") +  xlab("Year") + geom_point() 

This above plot does not give x axis from 1990, 1991, 1992,...,2005 as I want it to be. (not 1990, 1995, 2000,2005).

1 Answer 1

1

check out scale_x_continuous() - there is an option breaks inside which you can set to whatever you like. something like breaks = seq(1990,2005,1) should do.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks so much @davidski
glad it helped. for general axis/labels related questions you can refer to the scale_*_*() functions in the docs. here is also a cheat sheet for quick reference. also, pls consider marking this as solved - if my answer did indeed solve your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.