2015-02-10 58 views
1

我其實停留在提高我的圖表的可讀性(下面你可以看到他們的樣品),[R改善圖表數軸可讀性

我有超過15級的圖表與各種x軸和y軸長,兩者都是對數的。主要問題(如您在示例圖表中看到的)是x軸標籤密度和y軸稀疏刻度。

蜱按照行特設爲每個圖表定義:

scale_x_log10(breaks = c(1, seq(10,10000,10))) + scale_y_log10(breaks = c(1, seq(500,10000,500))) 

但因爲它完全是顯而易見的,它不能處理我的要求放置蜱「不會打擊,也不要那麼疏」 。如果我以任何其他方式定義標籤 param,ggplot將拋出一個錯誤(「中斷和標籤具有不等長度」)。

有沒有什麼辦法可以改善這種對數刻度標記?

非常感謝你提前

Badly readable x-axis and sparse y-axis

數據+代碼:

title1= "NM_001271428_1" 
x1= c(1,2,3,4.5,8.5,12,15.5,22.5,34.5,44.5,54,70.5,93.5,124.5,164,205.5,257.5,327,405.5,497.5,583.5,665.5,761.5,858) 
y1= c(50,78,75,103.5,178.5,240,294.5,405,586.5,712,810,987,1215.5,1494,1804,2055,2317.5,2616,2838.5,2985,2917.5,2662,2284.5,1716) 
title2= "NR_034168_1" 
x2= c(1,3,14.5,67) 
y2= c(10,12,43.5,134) 
title3= "NM_000016_4" 
x3= c(1,2,3,4,5,6,9,12,16,25,39.5,63.5,97,142,210.5,326.5,512) 
y3= c(19,36,51,60,70,78,108,132,160,225,316,444.5,582,710,842,979.5,1024) 
title4= "NM_004672_3" 
x4= c(1,2,3,4,5.5,8,10.5,13,15.5,18,22,27.5,35.5,43.5,53.5,65,79,104,136.5,173,209.5,253.5,313,402.5,508.5,630) 
y4= c(32,54,75,96,126.5,176,220.5,260,294.5,324,374,440,532.5,609,695.5,780,869,1040,1228.5,1384,1466.5,1521,1565,1610,1525.5,1260) 
title5= "NM_006243_3" 
x5= c(1,2,3,5.5,10,19.5,36.5,60,92,128,193,304,444.5,607.5) 
y5= c(22,28,39,66,110,195,328.5,480,644,768,965,1216,1333.5,1215) 
title6= "NM_198460_2" 
x6= c(1.5,3,4.5,6.5,10,13.5,16,20.5,29,41.5,63,90.5,128.5,187,261,346,446,543,636.5,731) 
y6= c(40.5,63,85.5,117,170,216,240,287,377,498,693,905,1156.5,1496,1827,2076,2230,2172,1909.5,1462) 
title7= "NM_001024212_1" 
x7= c(1,3,6,11.5,30.5,89) 
y7= c(53,18,30,46,91.5,178) 
title8= "NM_001040196_1" 
x8= c(1,2,4,10,19.5,32,62.5,129.5,250.5) 
y8= c(14,20,32,70,117,160,250,388.5,501) 
title9= "NM_001122681_1" 
x9= c(1,2,3,4.5,6,7,8,9,10.5,12,13,15,18.5,23.5,31,39,44.5,54,64.5,72.5,82,91.5,100.5,111.5,132.5,161.5,192,219.5,257,307,352,401,463,530,596.5,668,741.5,819,893) 
y9= c(93,86,123,175.5,222,252,280,306,346.5,384,403,450,536.5,634.5,806,975,1068,1242,1419,1522.5,1640,1738.5,1809,1895.5,2120,2422.5,2688,2853.5,3084,3377,3520,3609,3704,3710,3579,3340,2966,2457,1786) 
title10= "NM_001137552_1" 
x10= c(1,2,3,4,5.5,7,8,9,12,17.5,21.5,25,32.5,43,56,77,101.5,133.5,194,267.5,345.5,453.5,582.5,726) 
y10= c(69,52,75,96,121,147,160,171,216,280,322.5,350,422.5,516,616,770,913.5,1068,1358,1605,1727.5,1814,1747.5,1452) 
title11= "NM_001166109_1" 
x11= c(1,2,3,4.5,6.5,10,16.5,23,33.5,47,63,90.5,135,191,258,338.5,430,529.5,640,758.5) 
y11= c(31,42,60,81,110.5,160,247.5,322,435.5,564,693,905,1215,1528,1806,2031,2150,2118,1920,1517) 

p<- ggplot() + 
    xlab('r') + ylab('k') + ggtitle('5-Gram') + labs(color='Text', shape='Text') + 
geom_line(aes(x1, y1, color=title1)) + geom_point(aes(x1, y1, color=title1, shape=title1)) + 
#geom_line(aes(x2, y2, color=title2)) + geom_point(aes(x2, y2, color=title2, shape=title2)) + 
geom_line(aes(x3, y3, color=title3)) + geom_point(aes(x3, y3, color=title3, shape=title3)) + 
geom_line(aes(x4, y4, color=title4)) + geom_point(aes(x4, y4, color=title4, shape=title4)) + 
geom_line(aes(x5, y5, color=title5)) + geom_point(aes(x5, y5, color=title5, shape=title5)) + 
geom_line(aes(x6, y6, color=title6)) + geom_point(aes(x6, y6, color=title6, shape=title6)) + 
#geom_line(aes(x7, y7, color=title7)) + geom_point(aes(x7, y7, color=title7, shape=title7)) + 
geom_line(aes(x8, y8, color=title8)) + geom_point(aes(x8, y8, color=title8, shape=title8)) + 
#geom_line(aes(x9, y9, color=title9)) + geom_point(aes(x9, y9, color=title9, shape=title9)) + 
#geom_line(aes(x10, y10, color=title10)) + geom_point(aes(x10, y10, color=title10, shape=title10)) + 
#geom_line(aes(x11, y11, color=title11)) + geom_point(aes(x11, y11, color=title11, shape=title11)) + 
scale_x_log10(breaks = c(1, seq(10,10000,10))) + scale_y_log10(breaks = c(1, seq(500,10000,500))) + 
geom_point(size=3) + 
theme_bw() 
p 

回答

1

您可以檢查這個答案,適用於x軸:

ggplot2 y-axis ticks not showing up on a log scale

最好的, ZP

+0

謝謝,這使我成爲最簡單的解決方案 - 手動定義中斷:scale_y_log10(breaks = c(seq(50,500,50),seq(500,1000,100),seq(1000,2000 ,250),seq(2000,10000,500))) – 2015-02-10 12:37:18