2017-09-03 155 views
0

绘制折线图时,我对x轴有问题。如下图所示,我的标签太多了。ggplot2中的缩放x轴

Line graph

我尝试只包括使用seq()一些标签来补救方案,但我会遇到这样的错误:

ggplot(df, aes(x = date, y = measure, group = 1)) + 
    geom_line() + 
    theme_bw() + 
    theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) + 
    xlab("X-Axis") + 
    ylab("Y-Axis") + 
    scale_x_continuous(breaks = round(seq(min(df$date), max(df$date), by = 221.2), 1)) 

#> Error in seq.default(min(df$date), max(df$date), : 
#> 'from' must be a finite number 
#> In addition: Warning message: 
#> In seq.default(min(df$date), max(df$date), : 
#> NAs introduced by coercion 

有什么建议?如果有帮助,df$date被认为是一个角色。也许,我应该将其转换为数字或作为日期时间?

+1

请提供用于生产该地块您'df' – useR

回答