[英]How to plot line graph with a certain break of year variable in ggplot2
我想繪制從1990年到2005年在x軸上連續年份的折線圖。
# 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()
上面的圖沒有給出我想要的1990年,1991年,1992年,...,2005年的x軸。 (不是1990、1995、2000、2005)。
看看scale_x_continuous()
-里面有一個選項breaks
,您可以將其設置為自己喜歡的任何東西。 應該像breaks = seq(1990,2005,1)
這樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.