L D
L D

Reputation: 623

R improve chart log axis readability

i am actually stuck at improving readability of my charts (you can see sample of them below),

i have more than 15 charts with various x-axis a and y-axis lenght, both of them are logarithmic. Main problem (as you can see on that sample chart) is density of labels at x-axis and sparse ticks at y-axis.

Ticks are defined by following line ad hoc for each chart:

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

but as it is totally obvious, it cannot handle my request to place ticks "to not overwhelm and also not to be so sparse". If i define labels param in any other way than ticks, ggplot throws an error ("Breaks and labels have unequal lengths").

Is there any way how to improve this log scale labeling?

Thank you very much in advance

Badly readable x-axis and sparse y-axis

Data + code:

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

Upvotes: 1

Views: 191

Answers (1)

ZPB
ZPB

Reputation: 138

You can check this answer and apply to x axis:

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

Bests, ZP

Upvotes: 1

Related Questions