2015-04-02 206 views
2

我有連續值(請參閱下面的數據中的列log),我想用ggplot2在一行char中進行繪圖。我的代碼實際上做了這項工作但我的問題是y軸的值。實際上,這些值沒有均勻分佈,因此情節創建規模的錯誤視覺感知(例如參見下面的圖片的thirth情節綠色和藍色之間的空間線)ggplot2-如何繪製離散刻度軸值中的連續值?

enter image description here

我該如何解決這個問題?有沒有辦法迫使y軸組織從(0,1,2,3,4,5,6,7)離散值數據的數值?

這裏是我的數據

motor;trace;rules;time;log 
monetDBIE;1m;R2;1556;3,1 
monetDBIE;1m;R1;1590;3,2 
monetDBIE;1m;RDFS;15999;4,2 
monetDBIE;2m;R2;3319;3,5 
monetDBIE;2m;R1;3645;3,5 
monetDBIE;2m;RDFS;31239;4,4 
monetDBIE;5m;R2;9283;3,9 
monetDBIE;5m;R1;10398;4 
monetDBIE;5m;RDFS;85806;4,9 
Jena;1m;R1;227;2,3 
Jena;1m;R2;1203228;6 
Jena;1m;RDFS;21;1,3 
Jena;2m;R1;321;2,5 
Jena;2m;R2;5099199;6,7 
Jena;2m;RDFS;21;1,3 
Jena;5m;R1;629;2,7 
PGSQLIE;1m;R1;8149;3,9 
PGSQLIE;1m;R2;6548;3,8 
PGSQLIE;1m;RDFS;66116;4,8 
PGSQLIE;2m;R1;17029;4,2 
PGSQLIE;2m;R2;22523;4,3 
PGSQLIE;2m;RDFS;81155;4,9 
PGSQLIE;5m;R1;33483;4,5 
PGSQLIE;5m;R2;1504944;6,1 
PGSQLIE;5m;RDFS;891532;5,9 

這裏是我的代碼GGPLOT2

require("ggplot2") 

w <- read.csv(file="saturation/saturation.csv", head=TRUE, sep=";") 

p <- ggplot(data=w, aes(x=trace, y=log, colour=motor, shape=motor)) 

p <- p + geom_point(size=4) 

p <- p + geom_line(size=1,aes(group=motor)) 

p <- p + geom_text(aes(label=time), hjust=-0.2, vjust=1) 

p <- p + ggtitle("Insertion des triplets (R1, R2) et saturation RDFS dans triplestores") 

p <- p + scale_fill_continuous(guide = guide_legend(title = NULL)) 

p <- p + facet_grid(rules~.) 

p <- p + theme_bw() 

postscript(file = 'saturation.vs.eps') 

print (p) 

回答

1

真的希望離散Y的比例在這種情況下?如果更改w$log爲數字,圖形將「正確」的格式:

# Convert log variable to numeric and substitute commas with decimals 
w$log <- as.numeric(sub(",", ".", w$log, fixed=TRUE)) 

ggplot(data=w, aes(x=trace, y=log, colour=motor, shape=motor)) + 
    geom_point(size=4) + 
    geom_line(size=1,aes(group=motor)) + 
    geom_text(aes(label=time), hjust=-0.2, vjust=1) + 
    ggtitle("Insertion des triplets (R1, R2) et saturation RDFS dans triplestores") + 
    scale_fill_continuous(guide = guide_legend(title = NULL)) + 
    facet_grid(rules~.) + 
    theme_bw() 

如果你堅持一個離散y縮放比例,你可以使用scale_y_discrete(breaks=0:7, labels=0:7)

僅供參考 - 你可能想要從geom_text添加show_guide = FALSE刪除從傳說a ...也就是說,geom_text(aes(label = time), hjust=-0.2, vjust=1, show_guide=FALSE)

+0

(+1)爲你解答。轉換是一個很好的想法。我知道一個昏迷數字','被認爲是一個字符串'ggplot2'。謝謝 – 2015-04-02 18:32:39

相關問題