2015-06-18 8 views
0

我正在使用R Studio和easyGgplot2軟件包來創建一個線圖(Mac OSX,一切都更新到當前版本)。如何在R Studio中使用easyGgplot 2重新定位x軸上的點?

數據集我是這樣的:

Team  time   conc 
Soccer Pre-Season 5.738 
Soccer Post-Season 5.337 
Rugby Pre-Season 6.309 
Rugby Post-Season 5.889 
XC  Pre-Season 6.166 
XC  Post-Season 6.076 

我希望創造一個線圖,描繪了三條線(每隊一個)連接點從賽季前到後季濃度(濃)。我寫的代碼是:

ggplot2.lineplot(data=line, xName="time", yName="conc", groupName='Team', 
      size=2, linetype="solid", 
      addPoint=TRUE, color="black", 
      pointSize=4, pointFill="white", xtitle=" ", ytitle=" ", 
      mainTitle="NF-L Concentration (pg/mL)", 
      backgroundColor="white", removePanelGrid=T, 
      removePanelBorder=T, legendTitle="Team", 
      legendTitleFont=c(17, "bold", "Black"), 
      legendTextFont=c(17, "bold", "black"), 
      axisLine=c(0.5, "solid", "black")) 

但是,一旦我運行代碼,後季值出現在x軸的季前值的左側。本質上,它是倒退的。我該如何解決這個問題,使價值從季前到季後。我嘗試將我的CSV文件中的單元格重新排序,以便所有季前值都列在第一位。我甚至試圖在季後價值後列出所有這些。

任何幫助,非常感謝!

Ç

回答

0

2的解決方案可用於控制順序

解決方案1:

# specicify the orer of the levels before plotting 
line[, "time"] <- factor(line[, "time"], levels = c("Pre-Season", "Post-Season")) 
ggplot2.lineplot(data=line, xName="time", yName="conc", groupName='Team', 
     size=2, linetype="solid", 
     addPoint=TRUE, color="black", 
     pointSize=4, pointFill="white", xtitle=" ", ytitle=" ", 
     mainTitle="NF-L Concentration (pg/mL)", 
     backgroundColor="white", removePanelGrid=T, 
     removePanelBorder=T, legendTitle="Team", 
     legendTitleFont=c(17, "bold", "Black"), 
     legendTextFont=c(17, "bold", "black"), 
     axisLine=c(0.5, "solid", "black")) 

解決方案2:

# Create the plot and specify the order after 
myplot <- ggplot2.lineplot(data=line, xName="time", yName="conc", groupName='Team', 
     size=2, linetype="solid", 
     addPoint=TRUE, color="black", 
     pointSize=4, pointFill="white", xtitle=" ", ytitle=" ", 
     mainTitle="NF-L Concentration (pg/mL)", 
     backgroundColor="white", removePanelGrid=T, 
     removePanelBorder=T, legendTitle="Team", 
     legendTitleFont=c(17, "bold", "Black"), 
     legendTextFont=c(17, "bold", "black"), 
     axisLine=c(0.5, "solid", "black")) 
# specify the order and print the plot    
myplot + scale_x_discrete(limits=c("Pre-Season", "Post-Season")) 

好運!!