2016-01-06 70 views
1

我有這個代碼一個情節:r2空間比例

ex1 <- data.frame(Proc=rep(c("32", "16", "8", "4"), each=4), 
        CX=rep(c("C1", "C2", "C3", "C4"),4), 
        Time=c(15.58,16.94,23.25,24.11,9.6,10.09,12.32,12.95,5.72,6.11,6.87,6.85,3.51,3.54,3.54,3.54)) 


ggplot(ex1, aes(x=Proc, y=Time, colour=CX, 
          shape=CX, linetype=CX, group=CX)) + 
    geom_point() + 
    geom_line() + 
    theme_linedraw() + 
    theme(legend.position="bottom",axis.text.x = element_text(angle=45), axis.text.y = element_text(angle=0)) + coord_cartesian(ylim = c(0, 32)) + 
    scale_x_discrete(limits=c("4", "8", "16", "32")) 

The result is here

所以,我想,在x軸上的數字有比例的空間,因爲實際上在16和32之間的空間是相同的,我想顯示x軸4和8之間

:4 8 16 _ _ _ _ 32

我試圖:(沒有成功)

scale_x_discrete(breaks=c(seq(4,32,by=4)), limits=c("4", "8", "16", "32")) 

我該如何得到那個陰謀?我需要使用什麼功能?

回答

3

此:

ex1 <- data.frame(Proc=rep(c("32", "16", "8", "4"), each=4), 
        CX=rep(c("C1", "C2", "C3", "C4"),4), 
        Time=c(15.58,16.94,23.25,24.11,9.6,10.09, 
         12.32,12.95,5.72,6.11, 
         6.87,6.85,3.51,3.54,3.54,3.54)) 

ex1$Nproc <- as.numeric(as.character((ex1$Proc))) 
ggplot(ex1, aes(x=Nproc, y=Time, colour=CX, 
       shape=CX, linetype=CX, group=CX)) + 
    geom_point() + 
    geom_line() + 
    theme_linedraw() + 
    theme(legend.position="bottom", 
     axis.text.x = element_text(angle=45), 
     axis.text.y = element_text(angle=0)) + 
    coord_cartesian(ylim = c(0, 32)) + 
    scale_x_continuous(breaks=c(4,8,16,32),minor_breaks=NULL) 

產量:

enter image description here