2016-04-17 41 views
0

這些是我的簡單的數據(table.all):標籤上的x軸的barplot和非工作ggplot代碼

YR count 
2001  8 
2002  25 
2003  24 
2004  26 
2005  34 
2006  37 
2007  61 
2008  46 
2009  49 
2010  54 
2011  35 

我要繪製的數量,都與barplot和ggplot,但這barplot代碼無法繪製年x軸標籤:

barplot((table.all$count),axes=T,ylim=c(0,80), 
     cex.names=0.8,las=2, 
     main=paste("Number of peer-reviewed papers")) 

這ggplot代碼沒有告訴我任何東西,這是奇怪的,因爲我已經重複使用一些代碼,我已經使用,並已在工作其他數據:

ggplot(table.all, aes(x=YR,y=count)) + ylim(0,80) + xlim(2000,2016) 
    scale_y_continuous(expand = c(0, 0)) + 
    geom_bar(stat='identity') + 
    theme_bw(base_size = 16,base_family = "Times") + 
    annotate("text",x=2.5,y=14.9, 
      label="Total number of peer-reviewed papers",cex=7) 
+0

您是否嘗試過轉換的年份爲因子變量並應用該解決方案? http://stackoverflow.com/q/16350720/3250126 – loki

回答

0

看一看的barplotnames.arg參數:

barplot((table.all$count),axes=T,ylim=c(0,80), names.arg = table.all$YR, 
    cex.names=0.8,las=2, 
    main=paste("Number of peer-reviewed papers")) 

在你ggplot代碼要在+xlim只是失蹤。如果轉換YRfactor你得到你的刻度線:

table.all$YR <- as.factor(table.all$YR) 
ggplot(table.all,aes(x=YR,y=count)) + 
    scale_y_continuous(limits=c(0,75)) + 
    geom_bar(stat='identity') + 
    theme_bw(base_size = 16) + 
    ggtitle("Total number of peer-reviewed papers") 

ggplot with tick marks

+0

這工作。我唯一不能得到的就是我需要的擴展命令只能在y軸的最大極限處工作,同時不需要任何擴展ymin = 0。我需要y = 0與x軸平齊。 – Dag