从图中删除多余的灰色垂直线

时间:2019-12-25 15:28:42

标签: r ggplot2

当我使用ggplot进行绘图时,在数据图表之前的绘图上获得了灰色垂直线。任何有关如何删除它的想法将不胜感激。

ggplot(fitbit_data, aes(x = Date, y = Steps)) + 
  geom_bar(stat = "identity", fill = "green") + 
  labs(title = "My Steps", subtitle = " June - Dec 2019", 
       x = " Date", y = "Steps") + 
  scale_x_date(
    date_labels = "%b\n%Y",
    date_breaks = "1 month",
    limits = c(as.Date("2019-06-01"), as.Date("2019-12-31"))
  )

bar plot with redundant lines at front

1 个答案:

答案 0 :(得分:0)

就像数据被转换为因数一样,因此ggplot显示了一个分类的y轴,然后出现了重叠的标签,看起来像那些灰色列。

在读取数据时,请确保使用

df= read.table(..., 
               # assign appropriate data types by using
               colClasses = c(...),
               ... ,
               # it can also be adviseable to use
               stringsAsFactors = FALSE)