Reputation: 1111
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).
Upvotes: 0
Views: 1423
Reputation: 581
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.
Upvotes: 1