ggplot没有显示结束点

时间:2017-08-30 15:41:40

标签: r ggplot2

我有一个非常简单的数据集,由两列组成:

dates,Edges
Aug 09 2012,787615368
Aug 14 2012,1135686707
Aug 24 2012,1177338668
Sep 10 2012,1227146408
Sep 21 2012,1256398473
Oct 04 2012,1287176222
Oct 19 2012,1325057099
Nov 02 2012,1601829854
Dec 07 2012,1703931041
Jan 16 2013,1896596589
Feb 25 2013,2080968491
Apr 01 2013,2264510866
Apr 26 2013,2372135083
Jun 20 2013,2604769625

我使用以下代码绘制x-y平面中的每个点:

my_breaks = c("Aug 09 2012","Aug 14 2012","Aug 24 2012","Sep 10 2012","Sep 21 2012","Oct 04 2012",
              "Oct 19 2012","Nov 02 2012","Dec 07 2012","Jan 16 2013","Feb 25 2013","Apr 01 2013",
              "Apr 26 2013","Jun 20 2013")

snapshot_size_df$dates <- factor(snapshot_size_df$dates, levels = my_breaks)


ggplot() + 
    geom_point(data=snapshot_size_df, aes(dates, Edges, color='edges')) +
    theme(panel.background = element_rect(fill = "white"), legend.title=element_blank(), legend.position = "top", 
        legend.key = element_rect(fill=NA),
        axis.text.x = element_text(size=16, angle=90), text = element_text(size=16), axis.text.y = element_text(size=16)) +
    theme(axis.line.y = element_line(color="grey40", size = .5)) +
    theme(panel.grid.major = element_line(colour = "grey", linetype = "dotted")) +
    labs(y = "Count", x="") +
    scale_x_discrete(labels = my_breaks)

然而,它并没有显示最后三点: enter image description here

更新: 我应该注意,我使用Jupyter Notebook来运行我的代码。当另外两个人回答代码适用于他们时,我试图重启我的会话(在Jupyter Notebook的情况下内核),我的问题得到了解决。

1 个答案:

答案 0 :(得分:1)

这些值不在图表中,因此您可以设置ylim

ggplot() + 
    geom_point(data=snapshot_size_df, aes(dates, Edges, color='edges')) +
    theme(panel.background = element_rect(fill = "white"), legend.title=element_blank(), legend.position = "top", 
        legend.key = element_rect(fill=NA),
        axis.text.x = element_text(size=16, angle=90), text = element_text(size=16), axis.text.y = element_text(size=16)) +
    theme(axis.line.y = element_line(color="grey40", size = .5)) +
    theme(panel.grid.major = element_line(colour = "grey", linetype = "dotted")) +
    labs(y = "Count", x="") +
    scale_x_discrete(labels = my_breaks) + ylim(600000000, 3000000000)