2014-02-28 96 views
0

GGPLOT2問題,我有以下意指表:與Y軸

Sex Trait Average 
1 1 -N 9.042735 
2 2 -N 3.529577 
3 1  E 8.111111 
4 2  E 9.447887 
5 1  O 17.196580 
6 2  O 16.311800 
7 1  A 12.213680 
8 2  A 13.449440 
9 1  C 12.025640 
10 2  C 14.529580 

從我跑下圖:

library(ggplot2) 
plot <- ggplot(meansMatrix, aes(Trait, Average, colour= Sex,group= Sex)) + 
     geom_line(aes(linetype=Sex),size=1) + 
     geom_point(size=3,fill="white") + 
     scale_color_manual(values = c("black", "grey50")) + 
     scale_y_discrete(limits=c(0,18),breaks=seq(2,18,2.5),labels=seq(2,18,2.5)) + 
     scale_x_discrete(limits=c("-N","E","O","A","C")); plot 

enter image description here 有與y軸可見的問題。將變量Average設置爲數字後,通過更改參數(limits, breakslabels),我嘗試了不同的組合,但沒有成功。這是圖表是唯一彈出其他錯誤消息。

任何有關如何重新定位情節和顯示相應的休息的輸入將高度讚賞!

回答

3

使用scale_y_continuous

meansMatrix <- read.table(text=" Sex Trait Average 
1 1 -N 9.042735 
2 2 -N 3.529577 
3 1  E 8.111111 
4 2  E 9.447887 
5 1  O 17.196580 
6 2  O 16.311800 
7 1  A 12.213680 
8 2  A 13.449440 
9 1  C 12.025640 
10 2  C 14.529580", header=TRUE) 

meansMatrix$Sex <- factor(meansMatrix$Sex) 


library(ggplot2) 
p <- ggplot(meansMatrix, aes(Trait, Average, colour= Sex,group= Sex)) + 
    geom_line(aes(linetype=Sex),size=1) + 
    geom_point(size=3,fill="white") + 
    scale_color_manual(values = c("black", "grey50")) + 
    scale_y_continuous(limits=c(0,18),breaks=seq(2,18,2.5),labels=seq(2,18,2.5)) + 
    scale_x_discrete(limits=c("-N","E","O","A","C")) 

print(p) 

enter image description here